Next: , Previous: , Up: Preprocessing   [Contents][Index]


26.5 Macros

A macro is a fragment of code that has been given a name. Whenever the name is used, it is replaced by the contents of the macro. There are two kinds of macros. They differ mostly in what they look like when they are used. Object-like macros resemble data objects when used, function-like macros resemble function calls.

You may define any valid identifier as a macro, even if it is a C keyword. In the preprocessing stage, GCC does not know anything about keywords. This can be useful if you wish to hide a keyword such as const from an older compiler that does not understand it. However, the preprocessing operator defined (see defined) can never be defined as a macro.

The operator # is used in macros for stringification of an argument (see Stringification), and ## is used for concatenation of arguments into larger tokens (see Concatenation)