Is there any reason to prefer
#define MY_MACRO() ..stuff..
to
#define MY_MACRO ..stuff..
Don’t use macros is not a valid answer…
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Replacement only occurrs for a function-like macro if the macro name is followed by a left parenthesis. So, the following all invoke the function-like macro
MY_MACRO():But this would not:
It depends on how you are using the macro and what it is used for as to whether or not this is important. Ideally, your macros will all have distinct names; if you reserve all-uppercase identifiers for macros, then it shouldn’t matter whether you use an object-like or a function-like macro with zero parameters.
Aesthetically, it’s usually (but not always) cleaner not to have function-like macros that take zero parameters.