A question on Dir-4.9, in a case when a function-like macro and a function are not interchangeable. - 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:2012 and MISRA C:2023 guidelines (https://forum.misra.org.uk/forumdisplay.php?fid=21) +---- Forum: 7.4 Code design (https://forum.misra.org.uk/forumdisplay.php?fid=181) +---- Thread: A question on Dir-4.9, in a case when a function-like macro and a function are not interchangeable. (/showthread.php?tid=1492) |
A question on Dir-4.9, in a case when a function-like macro and a function are not interchangeable. - mz99 - 21-06-2019 Is the use of the function-like macro compliant (shown in Example 1 and 2 below) with Dir-4.9, in a case when a function-like macro and a function are not interchangeable? Example 1: ----------------------------------------------- #define ASSIGN( a, b ) ( ( a ) = ( b ) ) ----------------------------------------------- Example 2: ----------------------------------------------- #define MACRO( a, b ) int32_t var1; MACRO(var1,var2) ----------------------------------------------- The macros are not interchangeable with functions, because in Example 1, the arguments can't be modified if it is defined as a function, and in Example 2, compile error occurs because var2 is not defined. Re: A question on Dir-4.9, in a case when a function-like macro and a function are not interchangeable. - misra-c - 25-09-2019 The amplification for directive 4.9 states that the guideline "applies only where a function is permitted by the syntax and constraints of the language standard." Your examples cannot be re-written as functions and therefore directive 4.9 does not apply. There are no violations of directive 4.9. |