this is undefined behaviour so this macro expansion is difficult to predict. Another mechanism of failure can occur when the arguments within the body of a function-like macro are not fully parenthesized. The following example shows the macro without parenthesized arguments [2]: CUBE #define CUBE(X) (X * X * X) /* ... */ int a = CUBE(2 + 1); This example expands to: int a = (2 + 1 * 2 + 1 * 2 + 1) evaluates to 7 instead of the intended 27. 6.52.2 Guidance to language Replace macro-like functions with inline functions where possible. Although making a function inline only suggests to the compiler that the calls to the function be as fast as possible, the extent to which this is done is implementation-defined. Inline functions do offer consistent semantics and allow for better analysis by static analysis tools. Ensure that if a function-like macro must be used, that its arguments and body are parenthesized. Do not embed pre-processor directives or side-effects such as an assignment, increment/decrement, volatile access, or function call in a function-like macro. 6.53 Suppression of language-defined run-time checking [MXB] Does not apply to C since there are no language-defined runtime checks. 6.54 Provision of inherently unsafe operations [SKL] 6.54.1 Applicability to language C was designed for implementing system software some unsafe operations are inherent and common. 6.54.2 Guidance to language Follow the guidelines of TR 24772-1 clause 6.54.5.
this is undefined behaviour so this macro expansion is difficult to predict. Another mechanism of failure can occur when the arguments within the body of a function-like macro are not fully parenthesized. The following example shows the CUBE macro without parenthesized arguments [2]: #define CUBE(X) (X * X * X) /* ... */ int a = CUBE(2 + 1); This example expands to: int a = (2 + 1 * 2 + 1 * 2 + 1) evaluates to 7 instead of the intended 27. 6.52.2 Guidance to language Replace macro-like functions with inline functions where possible. Although making a function inline only suggests to the compiler that the calls to the function be as fast as possible, the extent to which this is done is implementation-defined. Inline functions do offer consistent semantics and allow for better analysis by static analysis tools. Ensure that if a function-like macro must be used, that its arguments and body are parenthesized. Do not embed pre-processor directives or side-effects such as an assignment, increment/decrement, volatile access, or function call in a function-like macro. 6.53 Suppression of language-defined run-time checking [MXB] Does not apply to C since there are no language-defined runtime checks. 6.54 Provision of inherently unsafe operations [SKL] 6.54.1 Applicability to language C was designed for implementing system software some unsafe operations are inherent and common. 6.54.2 Guidance to language Follow the guidelines of TR 24772-1 clause 6.54.5.
ISO-IECJTC1-SC22-WG23_N0713-tr24772-3-post-meeting-48-amended-20170504.docx