Identifier used as variable and function-like macro - Printable Version +- MISRA Discussion Forums (https://forum.misra.org.uk) +-- Forum: MISRA C (https://forum.misra.org.uk/forumdisplay.php?fid=4) +--- Forum: MISRA-C: 2004 rules (https://forum.misra.org.uk/forumdisplay.php?fid=17) +---- Forum: 6.19 Preprocessing Directives (https://forum.misra.org.uk/forumdisplay.php?fid=43) +---- Thread: Identifier used as variable and function-like macro (/showthread.php?tid=818) |
Identifier used as variable and function-like macro - dcrocker - 23-03-2011 I recently came across some code similar to the following: Code: #define Sum(_x, _y) ((_x) + (_y)) Re: Identifier used as variable and function-like macro - misra-c - 31-03-2011 Either of Rules 5.5 and 5.7 could be read as preventing Sum from being used as both a macro name and an object name, depending on the interpretation of "reused." Rule 5.5 would apply only when an identifier is used both as a macro name and the name of an object with static storage duration. The text of the rule focusses on reuse of an identifier when it names two different objects or functions but it does not preclude applicability to macro names. The more general Rule 5.7 would apply to all identifiers, whether or not any of their uses denote an object or function. The wording of these rules will be modified in a future version of MISRA C to make it clear that identifiers that are used as macro names shall not be reused as object or function names. |