This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

String.h Include guards



I have been running pc-lint on a Tiva TM4C project and I noticed when using <string.h> there is a pclint warning:

Issue 451: (Warning -- Header file 'C:\ti\ccsv6\tools\compiler\arm_5.1.9\include\string.h' repeatedly included but does not have a standard include guard [MISRA 2012 Directive 4.10, required])

looking inside string.h, the #endif for the include guard is not at the end of the file, but before this section for C++:

#if defined(__cplusplus) && !defined(_CPP_STYLE_HEADER)
using std::size_t;
using std::strlen;

...

#endif /* _CPP_STYLE_HEADER */


#endif /* ! _STRING */

I am using 5.1.9 but <string.h> is the same in 5.1.12.

Is there a reason why this section is outside the include guard, or is this a bug in the library file?

Thanks!

  • It is intentionally outside the include guard to support C++. If you look at the end of string.h, you'll see a comment that talks about MISRA and the fact that the block of declarations is outside the include guard. It also mentions that the extra code is strictly for C++, so MISRA should ignore it.
  • Archaeologist said:
    If you look at the end of string.h, you'll see a comment that talks about MISRA and the fact that the block of declarations is outside the include guard.

    This comment is not present in the string.h from compiler version 5.1.x.  It is present in compiler version 5.2.x.  For convenience, here it is ...

    /* using declarations must occur outside header guard to support including both
       C and C++-wrapped version of header; see _CPP_STYLE_HEADER check */
    /* this code is for C++ mode only and thus also not relevant for MISRA */

    While the comment is not present in 5.1.x, this explanation still applies. 

    Also, while the comment talks about MISRA, the situation is the same for static analysis tools such as pclint.

    Thanks and regards,

    -George

  • Thanks George/Archaeologist, it looks like I need to make sure pclint has those C++ related defines then for it to work correctly for C