ILE C/C++ Compiler Reference


ANSI/ISO Standard Predefined Macros

The ILE C/C++ compiler recognizes the following macros defined by the ANSI/ISO Standard. Unless otherwise specified, macros when defined have a value of 1.

 __DATE__ 
A character string literal containing the date when the source file was compiled. The date will be in the form:
   "Mmm dd yyyy"

where:

 __FILE__ 
Defined as a character string literal containing the name of the source file.

 __LINE__ 
Defined to be an integer representing the current source line number.

 __STDC__ 
Defined if the C compiler conforms to the ANSI standard. This macro is undefined if the language level is set to anything other than ANSI.

 __TIME__ 
Defined as a character string literal containing the time when the source file was compiled. The time will be in the form:
   "hh:mm:ss"

where:

 __cplusplus 
Defined when compiling a C++ program, indicating that the compiler is a C++ compiler. Note that this macro has no trailing underscores. This macro is not defined for C.

Notes:

  1. Predefined macro names cannot be the subject of a #define or #undef preprocessor directive.

  2. The predefined ANSI/ISO Standard macro names consist of two underscore (__) characters immediately preceding the name, the name in uppercase letters, and two underscore characters immediately following the name.

  3. The value of __LINE__ will change during compilation as the compiler processes subsequent lines of your source program.

  4. The value of __FILE__, and __TIME__ will change as the compiler processes any #include files that are part of your source program.

  5. You can also change __LINE__ and __FILE__ using the #line preprocessor directive.

Examples

The following printf() statements will display the values of the predefined macros __LINE__, __FILE__, __TIME__, and __DATE__ and will print a message indicating the program's conformance to ANSI standards based on __STDC__:



#include <stdio.h>
#ifdef __STDC__
#   define CONFORM    "conforms"
#else
#   define CONFORM    "does not conform"
#endif
int main(void)
{
  printf("Line %d of file %s has been executed\n", __LINE__, __FILE__);
  printf("This file was compiled at %s on %s\n", __TIME__, __DATE__);
  printf("This program %s to ANSI standards\n", CONFORM);
}

Related Information


[ Top of Page | Previous Page | Next Page | Table of Contents ]