I am trying to define a macro in the format
#define SUM(x,y) ({log_var = x; log_var += y;})
void main(void)
{
unsigned int log_var;
SUM(10,20);
}
Compilation of the same by ARMCC throws an error "Expected an expression" but compilation with GCC doesn't throw the error.
Is it the syntax ({<statements>}); is not allowed in ARMCC or is there any other reason for the same ?
The same disappears when the parentheses is removed. i.e {<statements>}
If you want to have a multi-statement macro body, the usual way is to have a one-iteration do while loop:
#define SUM(x,y) do {log_var = x; log_var += y;} while (0)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With