I have the following macro:
#define testMethod(a, b) \
if (a.length > b.length) \
return a; \
return b;
When I try to call it with:
NSString *s = testMethod(@"fir", @"sec");
I get an error:
"Excepted ";" at end of declaration"
Why?
ifis a statement, not an expression. It can’treturna value like that.You probably mean:
The extra parenthesis around the arguments on the right side are common, and are there to protect you against unexpected precendence-related incidents.
Also note that because the above is pre-processed by doing textual replacement, it will probably construct more objects than the equivalent function would.