Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Usage of underscore as argument of a macro function

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?

like image 849
winuall Avatar asked Apr 01 '15 20:04

winuall


People also ask

What are the types of arguments used with macro?

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 !

How do you use macros in arguments?

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).

Why are underscores used in C?

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);

What do you mean by macros with arguments?

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.


1 Answers

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.

like image 174
Iharob Al Asimi Avatar answered Oct 20 '22 00:10

Iharob Al Asimi