Doc. No. 2RDU00001 Rev C
Date: December 2005
JOINT STRIKE FIGHTER
AIR VEHICLE
C++ CODING STANDARDS
FOR THE SYSTEM DEVELOPMENT AND DEMONSTRATION PROGRAM
Document Number 2RDU00001 Rev C
December 2005
Copyright 2005 by Lockheed Martin Corporation.
DISTRIBUTION STATEMENT A: Approved for public release; distribution is unlimited.
Doc. No. 2RDU00001 Rev C
Date: December 2005
3
This page intentionally left blank
Doc. No. 2RDU00001 Rev C
Date: December 2005
4
TABLE OF CONTENTS
1 Introduction............................................................................................................................. 7
2 Referenced Documents........................................................................................................... 8
3 General Design...................................................................................................................... 10
3.1 Coupling & Cohesion ................................................................................................... 11
3.2 Code Size and Complexity............................................................................................ 12
4 C++ Coding Standards.......................................................................................................... 13
4.1 Introduction................................................................................................................... 13
4.2 Rules ............................................................................................................................. 13
4.2.1 Should, Will, and Shall Rules............................................................................... 13
4.2.2 Breaking Rules...................................................................................................... 13
4.2.3 Exceptions to Rules............................................................................................... 14
4.3 Terminology.................................................................................................................. 14
4.4 Environment.................................................................................................................. 17
4.4.1 Language............................................................................................................... 17
4.4.2 Character Sets ....................................................................................................... 17
4.4.3 Run-Time Checks ................................................................................................. 18
4.5 Libraries........................................................................................................................ 19
4.5.1 Standard Libraries................................................................................................. 19
4.6 Pre-Processing Directives............................................................................................. 20
4.6.1 #ifndef and #endif Pre-Processing Directives...................................................... 20
4.6.2 #define Pre-Processing Directive.......................................................................... 21
4.6.3 #include Pre-Processing Directive........................................................................ 21
4.7 Header Files .................................................................................................................. 22
4.8 Implementation Files .................................................................................................... 23
4.9 Style .............................................................................................................................. 23
4.9.1 Naming Identifiers................................................................................................ 24
4.9.1.1 Naming Classes, Structures, Enumerated types and typedefs .......................... 25
4.9.1.2 Naming Functions, Variables and Parameters.................................................. 26
4.9.1.3 Naming Constants and Enumerators................................................................. 26
4.9.2 Naming Files......................................................................................................... 26
4.9.3 Classes................................................................................................................... 27
4.9.4 Functions............................................................................................................... 27
4.9.5 Blocks ................................................................................................................... 28
4.9.6 Pointers and References........................................................................................ 28
4.9.7 Miscellaneous ....................................................................................................... 28
4.10 Classes........................................................................................................................... 29
4.10.1 Class Interfaces..................................................................................................... 29
4.10.2 Considerations Regarding Access Rights............................................................. 29
4.10.3 Member Functions................................................................................................ 29
4.10.4 const Member Functions....................................................................................... 30
4.10.5 Friends................................................................................................................... 30
4.10.6 Object Lifetime, Constructors, and Destructors ................................................... 30
4.10.6.1 Object Lifetime............................................................................................. 30
4.10.6.2 Constructors.................................................................................................. 31
4.10.6.3 Destructors.................................................................................................... 32
4.10.7 Assignment Operators........................................................................................... 33
Doc. No. 2RDU00001 Rev C
Date: December 2005
5
4.10.8 Operator Overloading ........................................................................................... 33
4.10.9 Inheritance............................................................................................................. 34
4.10.10 Virtual Member Functions................................................................................ 37
4.11 Namespaces................................................................................................................... 38
4.12 Templates...................................................................................................................... 39
4.13 Functions....................................................................................................................... 40
4.13.1 Function Declaration, Definition and Arguments................................................. 40
4.13.2 Return Types and Values...................................................................................... 41
4.13.3 Function Parameters (Value, Pointer or Reference)............................................. 42
4.13.4 Function Invocation.............................................................................................. 42
4.13.5 Function Overloading ........................................................................................... 43
4.13.6 Inline Functions .................................................................................................... 43
4.13.7 Temporary Objects................................................................................................ 44
4.14 Comments ..................................................................................................................... 44
4.15 Declarations and Definitions......................................................................................... 46
4.16 Initialization.................................................................................................................. 47
4.17 Types............................................................................................................................. 48
4.18 Constants....................................................................................................................... 48
4.19 Variables ....................................................................................................................... 49
4.20 Unions and Bit Fields.................................................................................................... 50
4.21 Operators....................................................................................................................... 51
4.22 Pointers & References................................................................................................... 52
4.23 Type Conversions ......................................................................................................... 54
4.24 Flow Control Structures................................................................................................ 56
4.25 Expressions................................................................................................................... 58
4.26 Memory Allocation....................................................................................................... 59
4.27 Fault Handling .............................................................................................................. 59
4.28 Portable Code................................................................................................................ 60
4.28.1 Data Abstraction ................................................................................................... 60
4.28.2 Data Representation.............................................................................................. 60
4.28.3 Underflow/Overflow............................................................................................. 61
4.28.4 Order of Execution................................................................................................ 61
4.28.5 Pointer Arithmetic................................................................................................. 61
4.29 Efficiency Considerations............................................................................................. 62
4.30 Miscellaneous ............................................................................................................... 62
5 Testing................................................................................................................................... 63
5.1.1 Subtypes................................................................................................................ 63
5.1.2 Structure................................................................................................................ 63
Appendix A................................................................................................................................... 66
Appendix B (Compliance).......................................................................................................... 142
Doc. No. 2RDU00001 Rev C
Date: December 2005
6
Table 1. Change Log
Revision
ID
Document
Date
Change
Authority
Affected
Paragraphs
Comments
0001 Rev B Oct 2005 K. Carroll All Original
0001 Rev C Nov 2005 K. Carroll Change log - Added Add change log.
Section 1, point 3
Rule 52
Rule 76
Rule 91
Rule 93
Rule 129
Rule 167
Rule 218
Appendix A, Rule 3
Table 2
Corrected spelling
errors.
Rule 159 - clarify that
"unary &" is intended.
Both binary and unary
forms of "&" exist.
Clarification is added
to specify that the rule
is concerned with the
unary form.
Rule 32 - clarification of
the scope of the rule. Also,
example added in appendix
for rule 32.
The rule does not
apply to a particular
partitioning of
template classes and
functions.
评论0