Start here

Home
About Klocwork
What's new
Fixed issues
Release notes
Installation

Reference

C/C++ checkers
Java checkers
C# checkers
MISRA C 2004 checkers
MISRA C++ 2008 checkers
MISRA C 2012 checkers
MISRA C 2012 checkers with Amendment 1
Commands
Metrics
Troubleshooting
Reference

Product components

C/C++ Integration build analysis
Java Integration build analysis
Desktop analysis
Refactoring
Klocwork Static Code Analysis
Klocwork Code Review
Structure101
Tuning
Custom checkers

Coding environments

Visual Studio
Eclipse for C/C++
Eclipse for Java
IntelliJ IDEA
Other

Administration

Project configuration
Build configuration
Administration
Analysis performance
Server performance
Security/permissions
Licensing
Klocwork Static Code Analysis Web API
Klocwork Code Review Web API

Community

View help online
Visit RogueWave.com
Klocwork Support
Rogue Wave Videos

Legal

Legal information

MISRA.TYPEDEF.NOT_UNIQUE

Typedef name is used for another entity.

MISRA C 2012 Rule 5.6: A typedef name shall be a unique identifier

Category: Required

Analysis: Decidable, System

Applies to: C90, C99

Amplification

A 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.

Rationale

Reusing a typedef name either as another typedef name or as the name of a function, object or enumeration constant, may lead to developer confusion.

Exception

The typedef name may be the same as the structure, union or enumeration tag name associated with the typedef.

Example

void 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 also

Rule 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.

Rationale

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.

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
}