Our website uses cookies to enhance your browsing experience.
Accept
to the top
>
>
>
V2614. MISRA. External identifiers...
menu mobile close menu
Additional information
toggle menu Contents

V2614. MISRA. External identifiers should be distinct.

Oct 04 2021

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

This diagnostic rule is relevant only for C.

Identifiers with external linkage should be easily distinguished within the limitations imposed by the used standard.

The limitations are as follows:

  • before standard C99: 6 significant characters, case-insensitive;
  • starting with standard C99: 31 significant characters, case-sensitive.

The example N1:

//         123456789012345678901234567890123
extern int shrtfn(void);                            // OK
extern int longfuncname(void);                      // Error in C90,
                                                    // but OK in C99
extern int longlonglonglonglongfunctionname1(void); // Error in both

Long identifiers make code harder to read and easier to confuse with automatically generated identifiers. When two identifiers differ only in characters that are not significant, this leads to undefined behavior.

Some implementations of compilers and linkers can have their limitations. The specific limitations are described in the documentation for the corresponding tools.

The example N2:

//         123456789012345678901234567890123
extern int longFuncName1(int);
extern int longFuncName2(int);

extern int AAA;
extern int aaa;

void foo(void)
{
  longFuncName2(AAA);
}

The code contains several errors at once—we examine the code based on the C90 standard:

  • The longFuncName1 and longFuncName2 identifiers are truncated down to the first 6 characters (longFu). As the result, the linker can interpret them as identical.
  • According to the C90 standard, identifiers are not always case-sensitive. As the result, the linker can interpret identifiers AAA and aaa as identical.
  • The foo function calls the longFuncName2 function and passes the AAA variable value as its parameter. This call leads to undefined behavior because each of these two identifiers cannot be interpreted as distinct.

Note. The diagnostic rule supports a special setting that allows you to disable checking the length of external identifiers.

To enable this setting, add the following comment to the source code or to the diagnostic rule configuration file .pvsconfig:

//+V2614 DISABLE_LENGHT_LIMIT_CHECK:YES

To disable the setting, use the comment:

//+V2614 DISABLE_LENGHT_LIMIT_CHECK:NO

This diagnostic is classified as:

  • MISRA-C-2012-5.1
  • MISRA-C-2023-5.1