Lines Matching refs:macro
75 The C preprocessor implements the macro language used to transform C
183 The C preprocessor, often known as @dfn{cpp}, is a @dfn{macro processor}
185 before compilation. It is called a macro processor because it allows
206 you are writing in. Modern versions of the GNU assembler have macro
496 they are ordinary identifiers. You can define a macro whose name is a
671 the directive that defines a macro.
673 The @samp{#} which begins a directive cannot come from a macro
674 expansion. Also, the directive name is not macro expanded. Thus, if
675 @code{foo} is defined as a macro expanding to @code{define}, that does
683 whitespace. For example, @samp{#define} must be followed by a macro
684 name and the intended expansion of the macro.
696 A header file is a file containing C declarations and macro definitions
713 declarations and macro definitions all or most of which are needed in
765 recognized, and macro names are not expanded. Thus, @code{@w{#include
824 Included files are not limited to declarations and macro definitions;
947 header, and the macro in the @samp{#ifndef} is still defined, it does
953 @cindex controlling macro
954 @cindex guard macro
955 The macro @code{FILE_FOO_SEEN} is called the @dfn{controlling macro} or
956 @dfn{guard macro}. In a user header file, the macro name should not
959 file, the macro name should contain the name of the file and some
983 ability to use a macro for the header name. This is called a
985 argument of @samp{#include}, you simply put a macro name there instead:
999 You must be careful when you define the macro. @samp{#define} saves
1000 tokens, not text. The preprocessor has no way of knowing that the macro
1008 not @samp{"} or @samp{<}, then the entire line is macro-expanded
1041 object-like macro which expands to a string constant. This will also
1141 A @dfn{macro} is a fragment of code which has been given a name.
1142 Whenever the name is used, it is replaced by the contents of the macro.
1147 You may define any valid identifier as a macro, even if it is a C
1152 macro, and C++'s named operators (@pxref{C++ Named Operators}) cannot be
1170 @cindex object-like macro
1174 An @dfn{object-like macro} is a simple identifier which will be replaced
1181 followed by the name of the macro and then the token sequence it should
1182 be an abbreviation for, which is variously referred to as the macro's
1190 defines a macro named @code{BUFFER_SIZE} as an abbreviation for the
1199 then the C preprocessor will recognize and @dfn{expand} the macro
1207 By convention, macro names are written in uppercase. Programs are
1211 The macro's body ends at the end of the @samp{#define} line. You may
1213 backslash-newline. When the macro is expanded, however, it will all
1228 There is no restriction on what can go in a macro body provided it
1231 you may get error messages from the C compiler when you use the macro.)
1251 When the preprocessor expands a macro name, the macro's expansion
1252 replaces the macro invocation, then the expansion is examined for more
1267 macro is expanded to produce the final result, @code{1024}.
1272 check to see whether it too contains macro names. Only when you
1274 more macro names.
1291 If the expansion of a macro contains its own name, either directly or
1301 are called @dfn{function-like macros}. To define a function-like macro,
1303 parentheses immediately after the macro name. For example,
1311 A function-like macro is only expanded if its name appears with a pair
1313 This can be useful when you have a function and a macro of the same
1324 Here the call to @code{foo()} will use the macro, but the function
1325 pointer will get the address of the real function. If the macro were to
1328 If you put spaces between the macro name and the parentheses in the
1329 macro definition, that does not define a function-like macro, it defines
1330 an object-like macro whose expansion happens to begin with a pair of
1340 macro. The third is the pair that was originally after the macro
1341 invocation. Since @code{lang_init} is an object-like macro, it does not
1348 @cindex arguments in macro definitions
1351 To define a macro that uses arguments, you insert @dfn{parameters}
1352 between the pair of parentheses in the macro definition that make the
1353 macro function-like. The parameters must be valid C identifiers,
1356 To invoke a macro that takes arguments, you write the name of the macro
1358 by commas. The invocation of the macro need not be restricted to a
1361 parameters in the macro definition. When the macro is expanded, each
1364 macro body.)
1366 As an example, here is a macro that computes the minimum of two numeric
1378 macro arguments. @xref{Macro Pitfalls}, for detailed explanations.)
1388 macro (array[x = y, x + 1])
1392 passes two arguments to @code{macro}: @code{array[x = y} and @code{x +
1397 All arguments to a macro are completely macro-expanded before they are
1398 substituted into the macro body. After substitution, the complete text
1401 about whether any function call is actually a macro invocation. You can
1425 @cindex empty macro arguments
1426 You can leave macro arguments empty; this is not an error to the
1428 You cannot leave out arguments entirely; if a macro takes two arguments,
1438 min() @error{} macro "min" requires 2 arguments, but only 1 given
1439 min(,,) @error{} macro "min" passed 3 arguments, but takes just 2
1442 Whitespace is not a preprocessing token, so if a macro @code{foo} takes
1446 function-like macro that takes a single argument be passed a space if an
1462 Sometimes you may want to convert a macro argument into a string
1464 can use the @samp{#} preprocessing operator instead. When a macro
1468 macro-expanded first. This is called @dfn{stringification}.
1477 Here is an example of a macro definition that uses stringification:
1494 @code{fprintf}. If @code{x} were a macro, it would be expanded in the
1517 There is no way to convert a macro argument into a character constant.
1519 If you want to stringify the result of expansion of a macro argument,
1535 macro-expanded first. But @code{s} is an ordinary argument to
1536 @code{xstr}, so it is completely macro-expanded before @code{xstr}
1538 @code{str} gets to its argument, it has already been macro-expanded.
1549 @samp{##} preprocessing operator performs token pasting. When a macro
1552 the two original tokens in the macro expansion. Usually both will be
1568 Both the tokens combined by @samp{##} could come from the macro body,
1571 macro argument. If either of the tokens next to an @samp{##} is a
1574 macro-expanded first. If the argument is empty, that @samp{##} has no
1583 end of a macro body.
1609 the string constant and once in the function name. A macro which takes the
1631 A macro can be declared to accept a variable number of arguments much as
1632 a function can. The syntax for defining the macro is similar to that of
1639 This kind of macro is called @dfn{variadic}. When the macro is invoked,
1641 macro has none), including any commas, become the @dfn{variable
1643 @code{@w{__VA_ARGS__}} in the macro body wherever it appears. Thus, we
1651 The variable argument is completely macro-expanded before it is inserted
1652 into the macro expansion, just like an ordinary argument. You may use
1657 If your macro is complicated, you may want a more descriptive name for
1661 The @code{eprintf} macro above could be written
1669 extension in the same macro.
1672 macro. We could define @code{eprintf} like this, instead:
1708 and the variable argument is left out when the @code{eprintf} macro is
1719 The above explanation is ambiguous about the case where the only macro
1728 can appear is in the replacement list of a variadic macro. It may not
1729 be used as a macro name, macro argument name, or within a different type
1730 of macro. It may also be forbidden in open text; the standard is
1785 This macro expands to the name of the current input file, in the form of
1790 macro.
1793 This macro expands to the current input line number, in the form of a
1794 decimal integer constant. While we call it a predefined macro, it's
1795 a pretty strange macro, since its ``definition'' changes with each
1825 manual). Neither of them is a macro; the preprocessor does not know the
1832 This macro expands to a string constant that describes the date on which
1842 This macro expands to a string constant that describes the time at
1851 In normal operation, this macro expands to the constant 1, to signify
1857 This macro is not defined if the @option{-traditional-cpp} option is used.
1868 This macro expands to the C Standard's version number, a long integer
1880 This macro is not defined if the @option{-traditional-cpp} option is
1884 This macro is defined, with value 1, if the compiler's target is a
1889 This macro is defined when the C++ compiler is in use. You can use
1891 or a C++ compiler. This macro is similar to @code{__STDC_VERSION__}, in
1893 of the 1998 C++ standard will define this macro to @code{199711L}. The
1899 This macro is defined with value 1 when preprocessing assembly
1916 This macro expands to sequential integral values starting from 0. In
1975 GCC defines this macro if and only if the @option{-ansi} switch, or a
1978 This macro exists primarily to direct GNU libc's header files to
1983 This macro expands to the name of the main input file, in the form
1988 This macro expands to a decimal integer constant that represents the
1989 depth of nesting in include files. The value of this macro is
1995 This macro is defined if the target uses the ELF object format.
1998 This macro expands to a string constant which describes the version of
2020 GCC defines this macro if functions declared @code{inline} will be
2027 GCC defines this macro if functions declared @code{inline} will be
2034 If this macro is defined, GCC supports the @code{gnu_inline} function
2037 neither macro is defined, an older version of GCC is being used:
2042 GCC defines this macro if and only if the data type @code{char} is
2044 file @file{limits.h} to work correctly. You should not use this macro
2048 Like @code{__CHAR_UNSIGNED__}, this macro is defined if and only if the
2052 This macro expands to a single token (not a string constant) which is
2060 This macro expands to a single token which is the prefix applied to
2065 This macro will have the correct definition even if
2088 this macro directly; instead, include the appropriate headers.
2106 This macro is defined, with value 1, when compiling a C++ source file
2111 This macro is defined, with value 1, when compiling a C++ source file
2113 compiling the file, then this macro will not be defined.
2116 This macro is defined, with value 1, if the compiler uses the old
2121 This macro is defined when compiling a C++ source file. It has the
2125 not collapse such symbols, this macro is defined with value 0. In
2126 general, user code should not need to make use of this macro; the
2127 purpose of this macro is to ease implementation of the C++ runtime
2137 This macro is defined, with value 1, when @option{-fstack-protector} is in
2141 This macro is defined, with value 2, when @option{-fstack-protector-all} is
2145 This macro is defined, with value 3, when @option{-fstack-protector-strong} is
2149 This macro expands to a string constant that describes the date and time
2182 provides a parallel macro with two underscores added at the beginning
2213 macro expanding to the appropriate punctuator.
2238 If a macro ceases to be useful, it may be @dfn{undefined} with the
2240 name of the macro to undefine. You use the bare macro name, even if the
2241 macro is function-like. It is an error if anything appears on the line
2242 after the macro name. @samp{#undef} has no effect if the name is not a
2243 macro.
2252 Once a macro has been undefined, that identifier may be @dfn{redefined}
2253 as a macro by a subsequent @samp{#define} directive. The new definition
2256 However, if an identifier which is currently a macro is redefined, then
2258 Two macro definitions are effectively the same if:
2260 @item Both are the same type of macro (object- or function-like).
2284 If a macro is redefined with a definition that is not effectively the
2286 macro to use the new definition. If the new definition is effectively
2288 instance, two different headers to define a common macro. The
2293 @cindex macro arguments and directives
2296 the arguments of a macro. The C and C++ standards declare that
2306 @samp{printf} had changed to be a function-like macro, and their code
2308 successfully process arbitrary directives within macro arguments in
2310 function-like macro invocation not present.
2312 If, within a macro invocation, that macro is redefined, then the new
2341 macro expansion, and point out certain cases in which the rules have
2357 When a macro is called with arguments, the arguments are substituted
2358 into the macro body and the result is checked, together with the rest of
2359 the input file, for more macro calls. It is possible to piece together
2360 a macro call coming partially from the macro body and partially from the
2372 an unbalanced open parenthesis in a macro body, it is possible to create
2373 a macro call that begins inside the macro body but ends outside of it.
2383 The ability to piece together a macro call can be useful, but the use of
2384 unbalanced open parentheses in a macro body is just confusing, and
2389 @cindex parentheses in macro bodies
2391 You may have noticed that in most of the macro definition examples shown
2392 above, each occurrence of a macro argument name had parentheses around
2394 entire macro definition. Here is why it is best to write macros that
2397 Suppose you define a macro as follows,
2429 Defining the macro as
2452 Parentheses around the entire macro definition prevent such problems.
2461 @cindex semicolons (after macro calls)
2463 Often it is desirable to define a macro that expands into a compound
2464 statement. Consider, for example, the following macro, that advances a
2477 Here backslash-newline is used to split the macro definition, which must
2479 be laid out if not part of a macro definition.
2481 A call to this macro might be @code{SKIP_SPACES (p, lim)}. Strictly
2502 The definition of the macro @code{SKIP_SPACES} can be altered to solve
2527 @cindex side effects (in macro arguments)
2529 Many C programs define a macro @code{min}, for ``minimum'', like this:
2535 When you use this macro with an argument containing a side effect,
2555 twice into the macro expansion. As a result, @code{foo} might be called
2558 intended. We say that @code{min} is an @dfn{unsafe} macro.
2580 careful when @emph{using} the macro @code{min}. For example, you can
2602 A @dfn{self-referential} macro is one whose name appears in its
2603 definition. Recall that all macro definitions are rescanned for more
2605 macro, it would produce an infinitely large expansion. To prevent this,
2606 the self-reference is not considered a macro call. It is passed into
2621 @code{(4 + foo)}. Therefore, this macro definition has the possibly
2627 not expect that it is a macro as well. The reader will come across the
2631 One common, useful use of self-reference is to create a macro which
2639 then the macro @code{EPERM} expands to @code{EPERM}. Effectively, it is
2641 can tell that it's a macro with @samp{#ifdef}. You might do this if you
2645 If a macro @code{x} expands to use a macro @code{y}, and the expansion of
2646 @code{y} refers to the macro @code{x}, that is an @dfn{indirect
2669 Each macro is expanded when it appears in the definition of the other
2670 macro, but not when it indirectly appears in its own definition.
2675 @cindex macro argument expansion
2676 @cindex prescan of macro arguments
2678 Macro arguments are completely macro-expanded before they are
2679 substituted into a macro body, unless they are stringified or pasted
2680 with other tokens. After substitution, the entire macro body, including
2683 macro calls in them.
2686 macro calls, they are expanded during the first scan. The result
2687 therefore contains no macro calls, so the second scan does not change
2689 single remaining scan would find the same macro calls and produce the
2693 self-referential macro is used in an argument of another macro
2694 (@pxref{Self-Referential Macros}): the self-referential macro would be
2706 Nested calls to a macro.
2708 We say that @dfn{nested} calls to a macro occur when a macro's argument
2709 contains a call to that very macro. For example, if @code{f} is a macro
2722 occur. If you @emph{want} to expand a macro, then stringify or
2723 concatenate its expansion, you can do that by causing one macro to call
2724 another macro that does the stringification or concatenation. For
2741 This can cause a macro expanded on the second scan to be called with the
2770 @cindex newlines in macro arguments
2772 The invocation of a function-like macro can extend over many logical
2802 arithmetic expressions, or whether a name is defined as a macro, or both
2926 Sometimes you wish to use some code if a macro is @emph{not} defined.
2949 macro name to specify which program you want, writing conditionals to
2950 test whether or how this macro is defined, and then controlling the
2951 state of the macro with command line options, perhaps set in the
2966 expression, rather than the mere existence of one macro. Its syntax is
3012 not a macro in an @samp{#if}.
3035 macro. @code{defined @var{name}} and @code{defined (@var{name})} are
3036 both expressions whose value is 1 if @var{name} is defined as a macro at
3040 @code{defined} is useful when you wish to test more than one macro for
3049 @code{__ns16000__} is defined as a macro.
3062 If the @code{defined} operator appears as a result of a macro expansion,
3157 @code{notdef} might be accidentally defined as a macro, and then the
3209 Neither @samp{#error} nor @samp{#warning} macro-expands its argument.
3221 and line number. All the tokens resulting from macro expansion are
3223 outermost macro was used. We intend to be more accurate in the future.
3260 @var{anything else} is checked for macro calls, which are expanded.
3322 produced as the result of macro expansion. @code{@w{_Pragma}} is an
3324 in a macro.
3387 If a poisoned identifier appears as part of the expansion of a macro
3503 will be no space between the @samp{#} and the directive name. If macro
3585 a matching closing quote. In particular, a macro may be defined with
3594 #define m This macro's fine and has an unmatched quote
3609 all leading and trailing horizontal whitespace from a macro's
3616 following the macro call. Similarly, the text at the end of a macro's
3617 expansion can run together with the text after the macro invocation to
3621 macro is expanded, but if the @option{-CC} option is passed on the
3623 implementation removes comments even before saving the macro
3625 observed effect is identical even in the function-like macro case.)
3631 macro replacement, do not expand.
3633 CPP replaces an unquoted object-like macro name with its replacement
3635 standard macro expansion, traditional macro expansion has no provision
3636 to prevent recursion. If an object-like macro appears unquoted in its
3640 offending macro invocation.
3658 This implementation removes all comments from macro arguments, unless
3668 is treated as an invocation of the macro @samp{f} with a single
3670 function-like macro that takes no arguments, you must not leave any
3673 If a macro argument crosses a new line, the new line is replaced with
3726 If a line that looks like a directive appears within macro arguments,
3743 Macro parameters that appear within string literals in the macro body.
3744 In traditional C macro replacement takes place within string literals,
3759 A function-like macro that appears without an argument list. In some
3761 that the macro is not expanded.
3874 @item Interpretation of the filename resulting from a macro-expanded
3879 @item Treatment of a @samp{#pragma} directive that after macro-expansion
3882 No macro expansion occurs on any @samp{#pragma} directive line, so the
3925 @item Significant initial characters in an identifier or macro name.
3935 @item Number of parameters in a macro definition and arguments in a macro call.
3996 sequences are ignored. (This is similar to the rules governing macro
4119 when you use a variable argument macro. This is forbidden by the 1999 C
4125 Formerly, in a macro expansion, if @samp{##} appeared before a variable
4127 in the macro invocation was empty, previous versions of CPP would
4179 cpp [@option{-D}@var{macro}[=@var{defn}]@dots{}] [@option{-U}@var{macro}]