Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Identifier used as variable and function-like macro
#1
I recently came across some code similar to the following:

Code:
#define Sum(_x, _y) ((_x) + (_y))

int Sum;
The identifier Sum is used both as the name of a function-like macro and as the name of a variable. Does this violate any MISRA-C 2004 rules? The occurrence of the identifier Sum in the variable declaration is not an instantiation of the macro, because the following preprocessing token is not '(' (section 6.8.3 of the C90 standard), so it appears that rule 19.8 does not apply. It might be considered that rule 5.6 is violated, but section 6.1.2.3 of the standard does not mention a namespace for preprocessor macro names. It could also be considered that rule 5.7 is violated, depending on the interpretation of the word "reused".
<r>David Crocker<br/>
Escher Technologies Ltd.<br/>
<URL url="http://www.eschertech.com">http://www.eschertech.com</URL></r>
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)