MISRA.DEFINE.NOT_DISTINCT.C90.2012MISRA C 2012 Rule 5.4: Macro identifiers shall be distinctIdentifier name is too long. C90 [Undefined 7], C99 [Unspecified 7; Undefined 28] Category: Required Analysis: Decidable, Single Translation Unit Applies to: C90, C99 AmplificationThis rule requires that, when a macro is being defined, its name be distinct from:
It also requires that the names of the parameters of a given macro be distinct from each other but does not require that macro parameters names be distinct across two different macros. The definition of distinct depends on the implementation and on the version of the C language that is being used:
RationaleT If two macro identifiers differ only in non-significant characters, the behaviour is undefined. Since macro parameters are active only during the expansion of their macro, there is no issue with parameters in one macro being confused with parameters in another macro. If portability is a concern, it would be prudent to apply this rule using the minimum limits specified in The Standard. Long macro identifiers may impair the readability of code. While many automatic code generation systems produce long macro identifiers, there is a good argument for keeping macro identifier lengths well below this limit. Note: In C99, if an extended source character appears in a macro name and that character does not have a corresponding universal character, The Standard does not specify how many characters it occupies. ExampleIn the following example, the implementation in question supports 31 significant case-sensitive characters in macro identifiers. /* 1234567890123456789012345678901********* Characters */ #define engine_exhaust_gas_temperature_raw egt_r #define engine_exhaust_gas_temperature_scaled egt_s /* Non-compliant */ /* 1234567890123456789012345678901********* Characters */ #define engine_exhaust_gas_temp_raw egt_r #define engine_exhaust_gas_temp_scaled egt_s /* Compliant */ See alsoRule 5.1, 5.2, 5.5 |