In C, what's the meaning of an underscore as a macro parameter?
#define FUNC(_) VALUE
Is it a dummy argument? any example for a use-case in which it'll fit?
There are two types of arguments: keyword and positional. Keyword arguments are assigned names in the macro definition; in the macro call, they are identified by name. Positional arguments are defined after the keyword !
To use a macro that expects arguments, you write the name of the macro followed by a list of actual arguments in parentheses, separated by commas. The number of actual arguments you give must match the number of arguments the macro expects. Examples of use of the macro min include min (1, 2) and min (x + 28, *p).
This is to reduce the possibility of confusion, by the same name beeing used for different purposes. Read a C language textbook, or XC compiler User Guide, about: Reserved keywords and symbols. Names starting with double underscore, like __builtin_... or __delay_ms(10);
Function-like macros can take arguments, just like true functions. To define a macro that uses arguments, you insert parameters between the pair of parentheses in the macro definition that make the macro function-like. The parameters must be valid C identifiers, separated by commas and optionally whitespace.
The _
has no special meaning, I suppose they used it because it looks like if the argument is not there.
The _
is just a valid identifier, and hence it's taken so the macro requires one parameter, but it keeps the macro definition looking as if there was no parameter.
#define FUNC(ignoredParameter) VALUE
would be exaclty the same.
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