6.10.3 Macro replacement

Previous Table of Contents

1899 Two replacement lists are identical if and only if the preprocessing tokens in both have the same number, ordering, spelling, and white-space separation, where all white-space separations are considered identical.

1900 An identifier currently defined as an object-like macro shall not be redefined by another #define preprocessing directive unless the second definition is an object-like macro definition and the two replacement lists are identical.

1901 Likewise, an identifier currently defined as a function-like macro shall not be redefined by another #define preprocessing directive unless the second definition is a function-like macro definition that has the same number and spelling of parameters, and the two replacement lists are identical.

1902 There shall be white-space between the identifier and the replacement list in the definition of an object-like macro.

1903 If the identifier-list in the macro definition does not end with an ellipsis, the number of arguments (including those arguments consisting of no preprocessing tokens) in an invocation of a function-like macro shall equal the number of parameters in the macro definition.

1904 Otherwise, there shall be more arguments in the invocation than there are parameters in the macro definition (excluding the ...).

1905 There shall exist a ) preprocessing token that terminates the invocation.

1906 The identifier __VA_ARGS__ shall occur only in the replacement-list of a function-like macro that uses the ellipsis notation in the argumentsparameters.

1907 A parameter identifier in a function-like macro shall be uniquely declared within its scope.

1908 The identifier immediately following the define is called the macro name.

1909 There is one name space for macro names.

1910 Any white-space characters preceding or following the replacement list of preprocessing tokens are not considered part of the replacement list for either form of macro.

1911 If a # preprocessing token, followed by an identifier, occurs lexically at the point at which a preprocessing directive could begin, the identifier is not subject to macro replacement.

1912 A preprocessing directive of the form

  # define identifier replacement-list new-line

defines an object-like macro that causes each subsequent instance of the macro name146) to be replaced by the replacement list of preprocessing tokens that constitute the remainder of the directive.

1913 A preprocessing directive of the form

  # define identifier lparen identifier-listopt ) replacement-list new-line
  # define identifier lparen ... ) replacement-list new-line
  # define identifier lparen identifier-list , ... ) replacement-list new-line

defines a function-like macro with arguments, similar syntactically to a function call.

1914 The parameters are specified by the optional list of identifiers, whose scope extends from their declaration in the identifier list until the new-line character that terminates the #define preprocessing directive.

1915 Each subsequent instance of the function-like macro name followed by a ( as the next preprocessing token introduces the sequence of preprocessing tokens that is replaced by the replacement list in the definition (an invocation of the macro).

1916 The replaced sequence of preprocessing tokens is terminated by the matching ) preprocessing token, skipping intervening matched pairs of left and right parenthesis preprocessing tokens.

1917 Within the sequence of preprocessing tokens making up an invocation of a function-like macro, new-line is considered a normal white-space character.

1918 The sequence of preprocessing tokens bounded by the outside-most matching parentheses forms the list of arguments for the function-like macro.

1919 The individual arguments within the list are separated by comma preprocessing tokens, but comma preprocessing tokens between matching inner parentheses do not separate arguments.

1920 If there are sequences of preprocessing tokens within the list of arguments that would otherwise act as preprocessing directives147), the behavior is undefined.

1921 If there is a ... in the identifier-list in the macro definition, then the trailing arguments, including any separating comma preprocessing tokens, are merged to form a single item: the variable arguments.

1922 The number of arguments so combined is such that, following merger, the number of arguments is one more than the number of parameters in the macro definition (excluding the ...).

1923 146) Since, by macro-replacement time, all character constants and string literals are preprocessing tokens, not sequences possibly containing identifier-like subsequences (see 5.1.1.2, translation phases), they are never scanned for macro names or parameters.

1924 147)Despite the name, a non-directive is a preprocessing directive.

Next

Created at: 2005-06-29 02:19:04 The text from WG14/N1124 is copyright © ISO