Why is this an issue?
Reusing 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.
Noncompliant code example
{
typedef unsigned char uint8_t;
}
{
typedef unsigned char uint8_t; // Noncompliant, redefinition
}
{
unsigned char uint8_t; // Noncompliant, reuse of uint8_t for another purpose
}
Compliant solution
typedef unsigned char uint8_t;
{
}
{
}
{
unsigned char myChar;
}
Resources
- MISRA C:2004, 5.3 - A typedef name shall be a unique identifier.
- MISRA C++:2008, 2-10-3 - A typedef name (including qualification, if any) shall be a unique identifier.