cmisrapc-lint

Use of modifier or type 'unsigned' outside of a typedef [MISRA 2012 Directive 4.6, advisory]


I am using MACRO #define for different data types as below.

#define CCP_BYTE    unsigned char
#define CCP_WORD    unsigned short
#define CCP_DWORD   unsigned long

Observed below warning at many statements (146 in number) wherever I am using these MACROs.

Use of modifier or type 'unsigned' outside of a typedef [MISRA 2012 Directive 4.6, advisory]

Use of modifier or type 'short' outside of a typedef [MISRA 2012 Directive 4.6, advisory]

Use of modifier or type 'long' outside of a typedef [MISRA 2012 Directive 4.6, advisory]

Observed warning at all the instance wherever I am typecasting test condition in if statement as below.

Use of modifier or type '_Bool' outside of a typedef [MISRA 2012 Directive 4.6, advisory]

if( !(bool) ChkStatus)
{
  /* execute if satisfy */    
}

I referred SO question which talks about this query for bool type. However, Is there any way other than disabling this rule to get rid of these warnings.


Solution

  • Rule 4.6 says that you should be using types for size and signedness, such as the stdint.h types, instead of default unsigned int etc.

    Meaning that you are allowed to create your own custom typedef if you are stuck with C90. Otherwise you should use stdint.h. This in turn means that your tool will only allow unsigned int etc together with a typedef, not together with a #define etc.

    As noted, the remark about bool is a false positive. Apparently it is a tool bug in Lint, which has been confirmed by the tool vendor as per comments in the linked question here.

    MISRA-C requires one boolean type to be used, but doesn't name it. Likely you have to configure the static analyser so that it knows what the bool type used is called. Using _Bool, bool or even a custom type is fine as far as MISRA is concerned.