Hi experts,
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>}"
Message was edited by: techguyz
This may or may not be your error (it could simply be a cut'n'paste problem) but you have a '.' rather than a ',' between your two arguments in the macro invocation. The result would certainly give problems according to the C standard.
Chris
Hi chris,
Its a typo error. But the actual compiled code is proper comma in between. The difference is that the same code is compiled by GCC but reported as error by ARMCC
The ({ ... }) syntax is not part of standard C or C++; it is a GNU extension called a "statement expression". But armcc allows you to turn on GNU extensions: http://infocenter.arm.com/help/topic/com.arm.doc.dui0472j/chr1359124965274.html