Friday, September 4, 2015

#define macro with a return value!

Can be done in gcc:

#define IS_DIGIT(x) ({\
int l;\
if (x == 1){\
l = 1;\
}else{\
l = 0;\
}\
l;\
})

The above macro returns an integer l. Can be used as follows:

int x = IS_DIGIT(1);

No comments:

Post a Comment