3

I am using LINT to check automatically generated C-sourcefiles. In these sourcefiles there is the use of those macros (simplified):

#define MACRO_CHECK(a, b, c) \ 
   ((a==b) ? b : (SET_VAR, c))

#define SET_VAR \
   global_var = 0 \

In the code, these macros are used like this:

if ( (x==0) && (MACRO(var1,var2,var3)==0) )
{
    //...
}

My LINT-analysis gives me the following message:

LINT Note 9007: side effects on right hand of logical operator

Since my Macro is writing a value to a global variable, the LINT-message itself is justified. However, because of architectural reasons, I know that I can ignore this message - because of this I want to exclude the macro from the check for Note 9007. Since I am usng autocode-generation, I have a hard time of injecting my LINT-comments (to disable the Lint-message) into the right place at the source file. A more clean approach would be, to exclude the macro from the check over my LINT-Ruleset. So I tried to add the following line to my LINT-ruleset:

-emacro((9007),MACRO_CHECK) 

However, this doesn't do the trick, since this excludes the code of the macro itself from the check, but it does not include the logical operator && and so it still gives me the Note 9007. Is there any way I can disable the error for all mesages which are somehow related to my macro?

Toby
  • 3,815
  • 14
  • 51
  • 67

1 Answers1

2

You should use

--emacro((9007),MACRO_CHECK)

Note the difference between -emacroand --emacro (taken from the PC-Lint manual):

-emacro( (#), symbol, ... ) inhibits, for a macro expression,

--emacro( (#), symbol, ... ) inhibits, for the entire expression, message # for each of the macro symbols given. The macros are expected to be expressions (syntactically).

So the additional - will do what you want in most cases, but you should be careful as you might end up suppressing messages in lines where the macro is used, which you don't want to suppress.

Consider the following:

if ( (x==0) && (MACRO_CHECK(var1,var2,var3)==0) && ((01234) == 0x1234) )
{
    //...
}

On my configuration (PC-Lint 9.00j using MISRA-checks) this will print me (between a lot of other stuff):

Note[1960]: Violates MISRA C++ 2008 Required Rule 5-14-1, side effects on right hand of logical operator: '&&'

Note[1960]: Violates MISRA C++ 2008 Required Rule 2-13-2, Octal constant used

01234 is the culprit for the second one of course. Now if I disable Note 1960 for the macro as pointed out with:

//lint --emacro((1960),MACRO_CHECK)

Both messages are gone, which, in this case, is not desired.

Arsenal
  • 333
  • 3
  • 15