logo资料库

清晰版本MISRA C_2012 Guidelines.pdf

第1页 / 共236页
第2页 / 共236页
第3页 / 共236页
第4页 / 共236页
第5页 / 共236页
第6页 / 共236页
第7页 / 共236页
第8页 / 共236页
资料共236页,剩余部分请下载后查看
MISRA C:2 012
Contents
1 The vision
2 Background to MISRA C
2.1 The popularity of C
2.2 Disadvantages of C
2.2.1 Language definition
2.2.2 Language misuse
2.2.3 Language misunderstanding
2.2.4 Run-time error checking
3 Tool selection
3.1 The C language and its compiler
3.2 Analysis tools
4 Prerequisite knowledge
4.1 Training
4.2 Understanding the compiler
4.3 Understanding the static analysis tools
5 Adopting and using MISRA C
5.1 Adoption
5.2 Software development process
5.2.1 Process activities required by MISRA C
5.2.2 Process activities expected by MISRA C
5.3 Compliance
5.3.1 Compiler configuration
5.3.2 Static analysis tool configuration
5.3.3 Investigating messages
5.4 Deviation procedure
5.5 Claiming compliance
6 Introduction to the guidelines
6.1 Guideline classification
6.2 Guideline categories
6.2.1 Mandatory guidelines
6.2.2 Required guidelines
6.2.3 Advisory guidelines
6.3 Organization of guidelines
6.4 Redundancy in the guidelines
6.5 Decidability of rules
6.6 Scope of analysis
6.7 Multi-organization projects
6.8 Automatically generated code
6.9 Presentation of guidelines
6.10 Understanding the source references
6.10.1 ISO C portability issue references
6.10.2 Other references
7 Directives
7.1 The implementation
7.2 Compilation and build
7.3 Requirements traceability
7.4 Code design
8 Rules
8.1 A standard C environment
8.2 Unused code
8.3 Comments
8.4 Character sets and lexical conventions
8.5 Identifiers
8.6 Types
8.7 Literals and constants
8.8 Declarations and definitions
8.9 Initialization
8.10 The essential type model
8.10.1 Rationale
8.10.2 Essential type
8.10.3 Composite operators and expressions
8.11 Pointer type conversions
8.12 Expressions
8.13 Side effects
8.14 Control statement expressions
8.15 Control flow
8.16 Switch statements
8.17 Functions
8.18 Pointers and arrays
8.19 Overlapping storage
8.20 Preprocessing directives
8.21 Standard libraries
8.22 Resources
9 References
Appendix A Summary of guidelines
Appendix B Guideline attributes
Appendix C Type safety issues with C
C.1 Type conversions
C.1.1 Implicit conversions
C.1.2 Explicit conversions
C.1.3 Concerns with conversions
C.2 Developer confusion
C.2.1 Type widening in integer promotion
C.2.2 Evaluation type confusion
C.2.3 Change of signedness in arithmetic operations
C.2.4 Change of signedness in bitwise operations
Appendix D Essential types
D.1 The essential type category of expressions
D.2 The essential type of character data
D.3 The signed and unsigned type of lowest rank (STLR and UTLR)
D.4 The essential type of bit-fields
D.5 The essential type of enumerations
D.6 The essential type of literal constants
D.7 The essential type of expressions
Appendix E Applicability to automatically generatedcode
E.1 Guideline categories for automatically generated code
E.1.1 Additional categories
E.1.2 Hiding identifiers
E.1.3 Octal constants
E.1.4 Compatible declarations with external linkage
E.1.5 Essential type
E.1.6 Loop counters
E.1.7 Labels and goto
E.1.8 Switch statements
E.1.9 Readability
E.2 Documentation requirements for automatic code generation tools
E.2.1 Implementation-defined behaviour and language extensions
E.2.2 The essential type model
E.2.3 Run-time errors
Appendix F Process and tools checklist
Appendix G Implementation-defined behaviour checklist
Appendix H Undefined and critical unspecified behaviour
H.1 Undefined behaviour
H.2 Critical unspecified behaviour
Appendix I Example deviation record
Appendix J Glossary
Licensed to: INTECS PAOLO PANARONI. 26 Mar 2013. Copy 1 of 1 MISRA C:2 012Guidelines for the use of the C language in critical systemsMarch 2013MISRA C 2012 cover A4.indd 117/03/2013 22:45:55
This copy of MISRA C:2012 Guidelines for the use of the C language in critical systems is issued to PAOLO PANARONI of INTECS at Via Umberto Forti, 5A, Montacchiello, Loc. Ospedaletto, PISA, I-56121. The file must not be altered in any way. No permission is given for distribution of this file. This includes but is not exclusively limited to making the copy available to others by email, placing it on a server for access by intra- or inter-net, or by printing and distributing hardcopies. Any such use constitutes an infringement of copyright. MISRA gives no guarantees about the accuracy of the information contained in this PDF version of the Guidelines. The published paper document should be taken as authoritative. Information is available from the MISRA web site on how to purchase printed copies of the document. Licensed to: INTECS PAOLO PANARONI. 26 Mar 2013. Copy 1 of 1 First published March 2013 by MIRA LimitedWatling StreetNuneatonWarwickshireCV10 0TUUK www.misra.org.uk© MIRA Limited 2013.“MISRA”, “MISRA C” and the triangle logo are registered trademarks of MIRA Limited, held on behalf of the MISRA Consortium.All rights reserved. No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical or photocopying, recording or otherwise without the prior written permission of the Publisher.ISBN 978-1-906400-10-1 paperbackISBN 978-1-906400-11-8 PDF British Library Cataloguing in Publication DataA catalogue record for this book is available from the British Library MISRA C 2012 cover A4.indd 217/03/2013 22:45:55
Licensed to: INTECS PAOLO PANARONI. 26 Mar 2013. Copy 1 of 1 iMISRA C:2 012Guidelines for the use of the C language in critical systemsMarch 2013 MISRA C 2012 final.indd i17/03/2013 22:52:08
Licensed to: INTECS PAOLO PANARONI. 26 Mar 2013. Copy 1 of 1 iiMISRA Miss ion StatementWe provide world-leading, best practice guidelines for the safe application of both embedded control systems and standalone software.MISRA, The Motor Industry Software Reliability Association, is a collaboration between manufacturers, component suppliers and engineering consultancies which seeks to promote best practice in developing safety-related embedded electronic systems and other software-intensive applications. To this end, MISRA publishes documents that provide accessible information for engineers and management, and holds events to permit the exchange of experiences between practitioners.www.misra.org.ukDisclaimerAdherence to the requirements of this document does not in itself ensure error-free robust software or guarantee portability and re-use.Compliance with the requirements of this document, or any other standard, does not of itself confer immunity from legal obligations.MISRA C 2012 final.indd ii17/03/2013 22:52:08
Licensed to: INTECS PAOLO PANARONI. 26 Mar 2013. Copy 1 of 1 iiiForewordA t fi rst sight, this third revision of the MISRA C Guidelines may seem somewhat daunting. Since it is roughly twice the size of the previous revision, one might think that it contains twice as many guidelines, and that compliance with those guidelines might take twice as much eff ort.In fact, the increase in the number of guidelines is relatively modest at around 10%. The remainder of the increase in size is due to improvements in the guidance given, such as:• Better rationales for guidelines;• More precise descriptions;• Code examples, showing compliance and non-compliance, for most of the guidelines;• More detailed guidance on compliance checking, and the deviation procedure;• Checklists that can be used to support a compliance statement.Finally, I would like to draw attention to the introductory sections of the document. These not only contain practical guidance on how to use MISRA C but, at the same time, have been made more concise than their predecessors. I encourage all users to familiarize themselves with this material.Steve Montgomery MA (Cantab), PhDChairman, MISRA C Working GroupMISRA C 2012 final.indd iii17/03/2013 22:52:08
Licensed to: INTECS PAOLO PANARONI. 26 Mar 2013. Copy 1 of 1 ivAcknowledgem entsThe MISRA consortium would like to thank the following individuals for their signifi cant contribution to the writing of this document:Dave BanhamRolls-Royce plc (previ ously of Als tom Grid)Andrew BanksIntuitiv e Cons ultingMark BradburyAero Engine Co ntrolsPaul BurdenProgramming Rese arch LtdMark Dawson-ButterworthZytek Automotive LtdM ike HennellLDRA LtdChris HillsPhaedr us Systems LtdSteve MontgomeryRicardo UK LtdChris TappLDRA Ltd (also Keylevel Consultants Ltd)Liz WhitingLDRA Ltd (previously of QinetiQ plc)The MISRA consortium also wishes to acknowledge contributions from the following individuals during the development and review process:Roberto BagnaraWilliam ForbesVoilmy LaurentKoki OnodaJohn BaileyTakao FutagamiFred LongPaulo PinheiroJohan BezemJim GimpelDaniel LundinMohanraj RagupathiGunter BlacheGilles GoulasGavin McCallPaul RigasMichael BurkeWolfgang von HansenDouglas MearnsAndrew ScholanAndrew BurnardTakahiro HashimotoSvante MöllerMarco SorichPaul ButlerDave HighamFrederic MondotTakuji TakumaMirko ConradShinya ItoJürgen MottokMartin ThompsonDavid CozensDavid JenningsYannick MoyTakafumi WakitaDavid CrockerPeter JestyAlexander MuchDavid WardGreg DavisGrzegorz KonopkoRobert MumméTetsuhiro YamamotoManoj DwivediTaneli KorhonenTadanori NakagawaNaoki YoshikawaCarl EdmundsJoel KuehnerGreg NewmanAchim Olaf ZacherParticular thanks are due to David Crocker for his signifi cant contribution towards the development of Appendix H.The descriptions of implementation-defi ned behaviours in Appendix G have been reproduced from versions of the ISO Standards published by BSI Standards Limited; the text is identical to that in the ISO versions. Permission to reproduce extracts from British Standards is granted by the BSI Standards Limited (BSI) under Licence No. 2013ET0003. No other use of this material is permitted. British Standards can be obtained in PDF or hard copy formats from the BSI online shop: www.bsigroup.com/Shop or by contacting BSI Customer Services for hard copies only: Tel: +44 20 8996 9001, Email: cservices@bsigroup.com.DokuWiki was used extensively during the drafting of this document. Our thanks go to all those involved in its development.This document was typeset using Open Sans. Open Sans is a trademark of Google and may be registered in certain jurisdictions. Digitized data copyright © 2010–2011, Google Corporation. Licensed under the Apache License, Version 2.0.MISRA C 2012 final.indd iv17/03/2013 22:52:08
Licensed to: INTECS PAOLO PANARONI. 26 Mar 2013. Copy 1 of 1 vContents1 The vision 12 Background to MISRA C 22.1 The popularity of C 22.2 Disadvantages of C 23 Tool selection 43.1 The C language and its compiler 43.2 Analysis tools 54 Prerequisite knowledge 64.1 Training 64.2 Understanding the compiler 64.3 Understanding the static analysis tools 65 Adopting and using MISRA C 85.1 Adoption 85.2 Software development process 85.3 Compliance 95.4 Deviation procedure 115.5 Claiming compliance 126 Introduction to the guidelines 136.1 Guideline classifi cation 136.2 Guideline categories 136.3 Organization of guidelines 146.4 Redundancy in the guidelines 146.5 Decidability of rules 146.6 Scope of analysis 156.7 Multi-organization projects 156.8 Automatically generated code 166.9 Presentation of guidelines 176.10 Understanding the source references 187 Directives 217.1 The implementation 217.2 Compilation and build 237.3 Requirements traceability 237.4 Code design 24MISRA C 2012 final.indd v17/03/2013 22:52:08
Licensed to: INTECS PAOLO PANARONI. 26 Mar 2013. Copy 1 of 1 vi8 Rules 378.1 A standard C environment 378.2 Unused code 398.3 Comments 458.4 Character sets and lexical conventions 468.5 Identifi ers 488.6 Types 588.7 Literals and constants 598.8 Declarations and defi nitions 638.9 Initialization 758.10 The essential type model 818.11 Pointer type conversions 938.12 Expressions 1038.13 Side eff ects 1088.14 Control statement expressions 1158.15 Control fl ow 1228.16 Switch statements 1308.17 Functions 1368.18 Pointers and arrays 1438.19 Overlapping storage 1538.20 Preprocessing directives 1558.21 Standard libraries 1658.22 Resources 1729 References 178Appendix A Summary of guidelines 180Appendix B Guideline attributes 189Appendix C Type safety issues with C 193Appendix D Essential types 196Appendix E Applicability to automatically generated code 202Appendix F Process and tools checklist 205Appendix G Implementation-defi ned behaviour checklist 206Appendix H Undefi ned and critical unspecifi ed behaviour 210Appendix I Example deviation record 220Appendix J Glossary 223MISRA C 2012 final.indd vi17/03/2013 22:52:08
分享到:
收藏