Envoyé par
JOINT STRIKE FIGHTER AIR VEHICLE C++ CODING STANDARDS
4.9.1 Naming Identifiers
The choice of identifier names should:
• Suggest the usage of the identifier.
• Consist of a descriptive name that is short yet meaningful.
• Be long enough to avoid name conflicts, but not excessive in length.
• Include abbreviations that are generally accepted.
Note: In general, the above guidelines should be followed. However, conventional usage of simple identifiers (i, x, y, p, etc.) in small scopes can lead to cleaner code and will therefore be permitted.
Additionally, the term ‘word’ in the following naming convention rules may be used to refer to a word, an acronym, an abbreviation, or a number.
AV Rule 45
All words in an identifier will be separated by the ‘_’ character.
Rationale: Readability and Style.
AV Rule 46 (MISRA Rule 11, Revised)
User-specified identifiers (internal and external) will not rely on significance of more than 64 characters.
Note: The C++ standard suggests that a minimum of 1,024 characters will be significant. [10]
AV Rule 47
Identifiers will not begin with the underscore character ‘_’.
Rationale: ‘_’ is often used as the first character in the name of library functions (e.g. _main, _exit, etc.) In order to avoid name collisions, identifiers should not begin with ‘_’.
Doc. No. 2RDU00001 Rev C
Date: December 2005
25
AV Rule 48
Identifiers will not differ by:
• Only a mixture of case
• The presence/absence of the underscore character
• The interchange of the letter ‘O’, with the number ‘0’ or the letter ‘D’
• The interchange of the letter ‘I’, with the number ‘1’ or the letter ‘l’
• The interchange of the letter ‘S’ with the number ‘5’
• The interchange of the letter ‘Z’ with the number 2
• The interchange of the letter ‘n’ with the letter ‘h’.
Rationale: Readability.
AV Rule 49
All acronyms in an identifier will be composed of uppercase letters.
Note: An acronym will always be in upper case, even if the acronym is located in a portion of an identifier that is specified to be lower case by other rules.
Rationale: Readability.
4.9.1.1 Naming Classes, Structures, Enumerated types and typedefs
AV Rule 50
The first word of the name of a class, structure, namespace, enumeration, or type created with typedef will begin with an uppercase letter. All others letters will be lowercase.
Rationale: Style.
Example:
class Diagonal_matrix { … }; // Only first letter is capitalized;
enum RGB_colors {red, green, blue}; // RGB is an acronym so all letters are un upper case
Exception: The first letter of a typedef name may be in lowercase in order to conform to a standard library interface or when used as a replacement for fundamental types (see AV Rule 209).
typename C::value_type s=0; // value_type of container C begins with a lower case
//letter in conformance with standard library typedefs
Doc. No. 2RDU00001 Rev C
Date: December 2005
26
4.9.1.2 Naming Functions, Variables and Parameters
AV Rule 51
All letters contained in function and variable names will be composed entirely of lowercase letters.
Rationale: Style.
Example:
class Example_class_name
{
public:
uint16 example_function_name (void);
private:
uint16 example_variable_name;
};
4.9.1.3 Naming Constants and Enumerators
AV Rule 52
Identifiers for constant and enumerator values shall be lowercase.
Example:
const uint16 max_pressure = 100;
enum Switch_position {up, down};
Rationale: Although it is an accepted convention to use uppercase letters for constants and enumerators, it is possible for third party libraries to replace constant/enumerator names as part of the macro substitution process (macros are also typically represented with uppercase letters).
Partager