Is it possible to have 2 macros with the same name, but different arguments? Something like this:
#define FI(value) do {l<<value; Doit(l); } while(0)
#define FI(value, level) do {l<<value ; Doit(l,level); } while(0)
Macros with arguments To create a macro with arguments, put them in parentheses separated by commas after the macro name, e.g. then BadSquare(3+4) would give 3+4*3+4, which evaluates to 19, which is probably not what we intended.
For portability, you should not have more than 31 parameters for a macro. The parameter list may end with an ellipsis (…).
The process to redefine a Macro is: Macro must be defined. When, you want to redefine the Macro, first of all, undefined the Macro by using #undef preprocessor directive. And, then define the Macro again by using #define preprocessor directive.
macro (array[x = y, x + 1]) passes two arguments to macro : array[x = y and x + 1] . If you want to supply array[x = y, x + 1] as an argument, you can write it as array[(x = y, x + 1)] , which is equivalent C code. All arguments to a macro are completely macro-expanded before they are substituted into the macro body.
It is not possible.
A symbol name cannot be redefined. Unlike functions macros cannot be overloaded. Think of it logically macros are for pure textual replacement, So how can you replace two different things for the same entity?
An alternative and better solution:
You can write a inline function for achieving the same result. It provides you additional advantage of type checking and saves you from the murky side effects of macros.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With