A question on Dir-4.9, in a case when a function-like macro and a function are not interchangeable.

Moderators: misra-c, david ward

Post Reply
mz99
Posts: 5
Joined: Fri Feb 01, 2019 5:58 am
Company: .

A question on Dir-4.9, in a case when a function-like macro and a function are not interchangeable.

Post by mz99 » Fri Jun 21, 2019 8:26 am

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.

Post Reply

Return to “7.4 Code design”