MISRA.CT.UNIQUE.IDIdentifier clashes with type name. MISRA C 2012 Rule 5.7: A tag name shall be a unique identifierCategory: Required Analysis: Decidable, System Applies to: C90, C99 AmplificationThe tag shall be unique across all name spaces and translation units. All declarations of the tag shall specify the same type. Multiple complete declarations of the same tag are only permitted by this rule if the tag is declared in a header file and that header file is included in multiple source files. ExampleReusing a tag name may lead to developer confusion. There is also undefined behaviour associated with reuse of tag names in C90 although this is not listed in The Standard’s Annex. This undefined behaviour was recognized in C99 as a constraint in Section 6.7.2.3. ExceptionThe tag name may be the same as the typedef name with which it is associated. Examplestruct stag { uint16_t a; uint16_t b; }; struct stag a1 = { 0, 0 }; /* Compliant - compatible with above */ union stag a2 = { 0, 0 }; /* Non-compliant - declares different type * from struct stag. * Constraint violation in C99 */ The following example also violates Rule 5.3 struct deer { uint16_t a; uint16_t b; }; void foo ( void ) { struct deer { uint16_t a; }; /* Non-compliant - tag "deer" reused */ } typedef struct coord { uint16_t x; uint16_t y; } coord; /* Compliant by Exception */ struct elk { uint16_t x; }; struct elk /* Non-compliant - declaration of different type * Constraint violation in C99 */ { uint32_t x; }; See alsoRule 5.6 MISRA-C 2004 Rule 5.4 (required): A tag name shall be a unique identifier.No tag name shall be reused either to define a different tag or for any other purpose within the program. ISO/IEC 9899:1990 [2] does not define the behaviour when an aggregate declaration uses a tag in different forms of type specifier (struct or union). Either all uses of the tag should be in structure type specifiers, or all uses should be in union type specifiers. Examplestruct stag { uint16_t a; uint16_t b; }; struct stag a1 = { 0, 0 }; /* Compliant - compatible with above */ union stag a2 = { 0, 0 }; /* Not compliant - not compatible with previous declarations */ void foo(void) { struct stag { uint16_t a; }; /* Not compliant - tag stag redefined */ } The same tag definition shall not be duplicated anywhere in the source code files even if the definitions are identical. Where the tag definition is made in a header file, and that header file is included in multiple source files, this rule is not violated. MISRA-C++ 2008 Rule 2-10-4 (required): A class, union or enum name (including qualification, if any) shall be a unique identifier.RationaleReusing a class, union or enum name, either as another type or for any other purpose, may lead to developer confusion. The class, union or enum name shall not be duplicated anywhere in the project, even if the declarations are identical. This rule is not violated when the definition is made in a header file, and that header file is included in multiple source files. Examplevoid f1 ( ) { class TYPE { }; } void f2 ( ) { float32_t TYPE; // Non-compliant } |