i'm trying to define the following macro:
#define UTF8_2B(c) if((0xc0 & c) == 0xc0){return 1;}
But i'm met with the error:
expected expression before ‘if’
The macro is called like so:
int i = UTF8_2B(c);
Where c is an unsigned char read from a file.
Why does this happen? Can you not use if else statements in macros? Also, I've read that it's not a good idea to use semicolon in your macros, but i didn't understand why. I'm new to c so the more thorough the answer the better.
variable = if (condition) …directly, so you can't use a macro that does it either. You're missing the else value too. Andreturnis wholly inappropriate in context. Remember: macro is text substitution. After preprocessing, the code must be valid C. - Jonathan Lefflerelsecase? - Jens Gustedt