Search code examples
cenumslintpc-lint

Can you get PC Lint to ignore certain special enums like 'myenum_min' and 'myenum_max'


So given the following code:

typedef enum
{
    myenum_a   = 1,
    myenum_b   = 2,
    myenum_c   = 3,
    myenum_max = 4
}myenum_t;

then later

myenum_t test;

switch (test)
{
    case myenum_a:
    {
        // do stuff
    }
    case myenum_b:
    {
        // do stuff
    }
    case myenum_c:
    default:
    {
        // do stuff
    }
}

When I run lint on this I get error 788: "'myenum_max' not used within defaulted switch".

I know I can use "// !e788" to ignore this rule for this particular switch statement, but that means:

  • this rule will be ignored for potential valid enums that are missing.
  • I have to add this line everywhere I add this kind of switch statement.

Or I can remove the rule entirely with "// -e788", but:

  • Again this rule will be ignored for valid missing enums for ALL types of enums - so even worse.

What I really want, but not sure how to do it (or if it exists) is to ignore the rule for a given enum something like:

typedef enum
{
    myenum_a   = 1,
    myenum_b   = 2,
    myenum_c   = 3,
    myenum_max = 4   // !eXXX  - ignore this enum
}myenum_t;

Is that possible?


Solution

  • PC-Lint does not provide a special command to suppress messages regarding enum values, BUT it provides the option -estring(#, string) to suppress a specific error message containing the specified string. This can be used for suppressing specific messages on specific enum values.

    For your example this should work:

    //lint -estring(788, myenum_max)
    

    Addendum

    The option -estring(#, string) has been introduced with PC-Lint version 9.00.