MISRA.TYPEDEF.NOT_UNIQUETypedef name is used for another entity.
MISRA C 2012 Rule 5.6: A typedef name shall be a unique identifierCategory: Required Analysis: Decidable, System Applies to: C90, C99 AmplificationA typedef name shall be unique across all name spaces and translation units. Multiple declarations of the same typedef name are only permitted by this rule if the type definition is made in a header file and that header file is included in multiple source files. RationaleReusing a typedef name either as another typedef name or as the name of a function, object or enumeration constant, may lead to developer confusion. ExceptionThe typedef name may be the same as the structure, union or enumeration tag name associated with the typedef. Examplevoid func ( void ) { { typedef unsigned char u8_t; } { typedef unsigned char u8_t; /* Non-compliant - reuse */ } } typedef float mass; void func1 ( void ) { float32_t mass = 0.0f; /* Non-compliant - reuse */ } typedef struct list { struct list *next; uint16_t element; } list; /* Compliant - exception */ typedef struct { struct chain { struct chain *list; uint16_t element; } s1; uint16_t length; } chain; /* Non-compliant - tag "chain" not * associated with typedef */ See alsoRule 5.7 MISRA-C 2004 Rule 5.3 (required): A typedef name shall be a unique identifier.Name of typedef is not unique. No typedef name shall be reused either as a typedef name or for any other purpose. Example{ typedef unsigned char uint8_t; } { typedef unsigned char uint8_t; /* Not compliant - redefinition */ } { unsigned char uint8_t; /* Not compliant - reuse of uint8_t */ } typedef names shall not be reused anywhere within a program. The same typedef shall not be duplicated anywhere in the source code files even if the declarations are identical. Where the type 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-3 (required): A typedef name (including qualification, if any) shall be a unique identifier.RationaleReusing a typedef name either as another typedef name or for any other purpose may lead to developer confusion. The same typedef shall not be duplicated anywhere in the project, even if the declarations are identical. Note that where the type definition is made in a header file, and that header file is included in multiple source files, this rule is not violated. Example// f1.cc namespace NS1 { typedef int16_t WIDTH; } // f2.cc namespace NS2 { float32_t WIDTH; // Compliant - // NS2::WIDTH is not the same as NS1::WIDTH } void f1 ( ) { typedef int32_t TYPE; } void f2 ( ) { float32_t TYPE; // Non-compliant } |