Function-like Macros
3.2 Function-like Macros
You can also define macros whose use looks like a function call. These are called function-like macros. To define a function-like macro, you use the same ‘#define
’ directive, but you put a pair of parentheses immediately after the macro name. For example,
#define lang_init() c_init() lang_init() ==> c_init()
A function-like macro is only expanded if its name appears with a pair of parentheses after it. If you write just the name, it is left alone. This can be useful when you have a function and a macro of the same name, and you wish to use the function sometimes.
extern void foo(void);
#define foo() /* optimized inline version */
...
foo();
funcptr = foo;
Here the call to foo()
will use the macro, but the function pointer will get the address of the real funct