What is the difference between a preprocessor macro with no arguments, and one with zero arguments

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():

MY_MACRO()
MY_MACRO ( )
MY_MACRO
( )

But this would not:

MY_MACRO SomethingElse

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.

Leave a Comment