>
>
>
V2619. MISRA. Typedef names should be u…


V2619. MISRA. Typedef names should be unique across all name spaces.

This diagnostic rule is based on the software development guidelines developed by MISRA (Motor Industry Software Reliability Association).

This rule only applies to C. Typedef names should be unique across all name spaces. The repeated use of 'typedef' name can confuse the developer.

Let's look at the example:

void foo()
{
  {
    typedef unsigned char Id;
    Id x = 128;                // ok
  }
  {
    typedef char Id;
    Id x = 128;                // error
  }
}

The 'unsigned char' type ranges from 0 to 255. The 'signed char' type has a range between -128 and 127. After working with the second 'typedef', the programmer may forget that the type has changed. This may lead to an error.

Here's the second example:

void foo()
{
  {
    typedef unsigned char uId;
    uId x = 128;                // ok
  }
  {
    typedef singned char sId;
    sId x = 128;                // ok
  }
}

In this case, it is more difficult to make a mistake, since the 'typedef' names differ.

As an exception, you can duplicate the 'typedef' name when you declare 'struct', 'union' or 'enum' if they are associated with this particular 'typedef'.

typedef struct list
{
  struct list* next;
  int element;
} list;               // ok

This diagnostic is classified as:

  • MISRA-C-5.6