6.10.1 Conditional inclusion

Previous Table of Contents "New C Standard" commentary

1869 The expression that controls conditional inclusion shall be an integer constant expression except that: it shall not contain a cast;

1870 it shall not contain a cast;

1871 identifiers (including those lexically identical to keywords) are interpreted as described below;141)

1872 and it may contain unary operator expressions of the form

  defined identifier

or

  defined ( identifier )

which evaluate to 1 if the identifier is currently defined as a macro name (that is, if it is predefined or if it has been the subject of a #define preprocessing directive without an intervening #undef directive with the same subject identifier), 0 if it is not.

1873 Each preprocessing token that remains after all macro replacements have occurred shall be in the lexical form of a token (6.4).

1874 141) Because the controlling constant expression is evaluated during translation phase 4, all identifiers either are or are not macro names— there simply are no keywords, enumeration constants, etc.

1875 Preprocessing directives of the forms

  # if   constant-expression new-line groupopt
  # elif constant-expression new-line groupopt

check whether the controlling constant expression evaluates to nonzero.

1876 Prior to evaluation, macro invocations in the list of preprocessing tokens that will become the controlling constant expression are replaced (except for those macro names modified by the defined unary operator), just as in normal text.

1877 If the token defined is generated as a result of this replacement process or use of the defined unary operator does not match one of the two specified forms prior to macro replacement, the behavior is undefined.

1878 After all replacements due to macro expansion and the defined unary operator have been performed, all remaining identifiers (including those lexically identical to keywords) are replaced with the pp-number 0, and then each preprocessing token is converted into a token.

1879 The resulting tokens compose the controlling constant expression which is evaluated according to the rules of 6.6, except that all signed integer types and all unsigned integer types act as if they have the same representation as, respectively, the types intmax_t and uintmax_t defined in the header <stdint.h>.

1880 For the purposes of this token conversion and evaluation, all signed integer types and all unsigned integer types act as if they have the same representation as, respectively, the types intmax_t and uintmax_t defined in the header <stdint.h>.142)

1881 This includes interpreting character constants, which may involve converting escape sequences into execution character set members.

1882 Whether the numeric value for these character constants matches the value obtained when an identical character constant occurs in an expression (other than within a #if or #elif directive) is implementation-defined.143)

1883 Also, whether a single-character character constant may have a negative value is implementation-defined.

1884 Preprocessing directives of the forms

  # ifdef  identifier new-line groupopt
  # ifndef identifier new-line groupopt

check whether the identifier is or is not currently defined as a macro name.

1885 Their conditions are equivalent to #if defined identifier and #if !defined identifier respectively.

1886 142) Thus on an implementation where INT_MAX is 0x7FFF and UINT_MAX is 0xFFFF, the constant 0x8000 is signed and positive within a #if expression even though it is unsigned in translation phase 7.

1887 143) Thus, the constant expression in the following #if directive and if statement is not guaranteed to evaluate to the same value in these two contexts.


  #if 'z' - 'a' == 25
  if ('z' - 'a' == 25)

1888 Each directive's condition is checked in order.

1889 If it evaluates to false (zero), the group that it controls is skipped: directives are processed only through the name that determines the directive in order to keep track of the level of nested conditionals;

1890 directives are processed only through the name that determines the directive in order to keep track of the level of nested conditionals;

1891 the rest of the directives' preprocessing tokens are ignored, as are the other preprocessing tokens in the group.

1892 Only the first group whose control condition evaluates to true (nonzero) is processed.

1893 If none of the conditions evaluates to true, and there is a #else directive, the group controlled by the #else is processed;

1894 lacking a #else directive, all the groups until the #endif are skipped.144)

1895 Forward references: macro replacement (6.10.3), source file inclusion (6.10.2), largest integer types (7.18.1.5).

Next

Created at: 2008-01-30 02:39:44 The text from WG14/N1256 is copyright © ISO