cpp: Standard Predefined Macros

1 
1 3.7.1 Standard Predefined Macros
1 --------------------------------
1 
1 The standard predefined macros are specified by the relevant language
1 standards, so they are available with all compilers that implement those
1 standards.  Older compilers may not provide all of them.  Their names
1 all start with double underscores.
1 
1 '__FILE__'
1      This macro expands to the name of the current input file, in the
1      form of a C string constant.  This is the path by which the
1      preprocessor opened the file, not the short name specified in
1      '#include' or as the input file name argument.  For example,
1      '"/usr/local/include/myheader.h"' is a possible expansion of this
1      macro.
1 
1 '__LINE__'
1      This macro expands to the current input line number, in the form of
1      a decimal integer constant.  While we call it a predefined macro,
1      it's a pretty strange macro, since its "definition" changes with
1      each new line of source code.
1 
1    '__FILE__' and '__LINE__' are useful in generating an error message
1 to report an inconsistency detected by the program; the message can
1 state the source line at which the inconsistency was detected.  For
1 example,
1 
1      fprintf (stderr, "Internal error: "
1                       "negative string length "
1                       "%d at %s, line %d.",
1               length, __FILE__, __LINE__);
1 
1    An '#include' directive changes the expansions of '__FILE__' and
1 '__LINE__' to correspond to the included file.  At the end of that file,
1 when processing resumes on the input file that contained the '#include'
1 directive, the expansions of '__FILE__' and '__LINE__' revert to the
1 values they had before the '#include' (but '__LINE__' is then
1 incremented by one as processing moves to the line after the
1 '#include').
1 
1    A '#line' directive changes '__LINE__', and may change '__FILE__' as
1 well.  ⇒Line Control.
1 
1    C99 introduced '__func__', and GCC has provided '__FUNCTION__' for a
1 long time.  Both of these are strings containing the name of the current
1 function (there are slight semantic differences; see the GCC manual).
1 Neither of them is a macro; the preprocessor does not know the name of
1 the current function.  They tend to be useful in conjunction with
1 '__FILE__' and '__LINE__', though.
1 
1 '__DATE__'
1      This macro expands to a string constant that describes the date on
1      which the preprocessor is being run.  The string constant contains
1      eleven characters and looks like '"Feb 12 1996"'.  If the day of
1      the month is less than 10, it is padded with a space on the left.
1 
1      If GCC cannot determine the current date, it will emit a warning
1      message (once per compilation) and '__DATE__' will expand to
1      '"??? ?? ????"'.
1 
1 '__TIME__'
1      This macro expands to a string constant that describes the time at
1      which the preprocessor is being run.  The string constant contains
1      eight characters and looks like '"23:59:01"'.
1 
1      If GCC cannot determine the current time, it will emit a warning
1      message (once per compilation) and '__TIME__' will expand to
1      '"??:??:??"'.
1 
1 '__STDC__'
1      In normal operation, this macro expands to the constant 1, to
1      signify that this compiler conforms to ISO Standard C.  If GNU CPP
1      is used with a compiler other than GCC, this is not necessarily
1      true; however, the preprocessor always conforms to the standard
1      unless the '-traditional-cpp' option is used.
1 
1      This macro is not defined if the '-traditional-cpp' option is used.
1 
1      On some hosts, the system compiler uses a different convention,
1      where '__STDC__' is normally 0, but is 1 if the user specifies
1      strict conformance to the C Standard.  CPP follows the host
1      convention when processing system header files, but when processing
1      user files '__STDC__' is always 1.  This has been reported to cause
1      problems; for instance, some versions of Solaris provide X Windows
11      headers that expect '__STDC__' to be either undefined or 1.  ⇒
      Invocation.
1 
1 '__STDC_VERSION__'
1      This macro expands to the C Standard's version number, a long
1      integer constant of the form 'YYYYMML' where YYYY and MM are the
1      year and month of the Standard version.  This signifies which
1      version of the C Standard the compiler conforms to.  Like
1      '__STDC__', this is not necessarily accurate for the entire
1      implementation, unless GNU CPP is being used with GCC.
1 
1      The value '199409L' signifies the 1989 C standard as amended in
1      1994, which is the current default; the value '199901L' signifies
1      the 1999 revision of the C standard; the value '201112L' signifies
1      the 2011 revision of the C standard; the value '201710L' signifies
1      the 2017 revision of the C standard (which is otherwise identical
1      to the 2011 version apart from correction of defects).
1 
1      This macro is not defined if the '-traditional-cpp' option is used,
1      nor when compiling C++ or Objective-C.
1 
1 '__STDC_HOSTED__'
1      This macro is defined, with value 1, if the compiler's target is a
1      "hosted environment".  A hosted environment has the complete
1      facilities of the standard C library available.
1 
1 '__cplusplus'
1      This macro is defined when the C++ compiler is in use.  You can use
1      '__cplusplus' to test whether a header is compiled by a C compiler
1      or a C++ compiler.  This macro is similar to '__STDC_VERSION__', in
1      that it expands to a version number.  Depending on the language
1      standard selected, the value of the macro is '199711L' for the 1998
1      C++ standard, '201103L' for the 2011 C++ standard, '201402L' for
1      the 2014 C++ standard, '201703L' for the 2017 C++ standard, or an
1      unspecified value strictly larger than '201703L' for the
1      experimental languages enabled by '-std=c++2a' and '-std=gnu++2a'.
1 
1 '__OBJC__'
1      This macro is defined, with value 1, when the Objective-C compiler
1      is in use.  You can use '__OBJC__' to test whether a header is
1      compiled by a C compiler or an Objective-C compiler.
1 
1 '__ASSEMBLER__'
1      This macro is defined with value 1 when preprocessing assembly
1      language.
1