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 is in the form:
where:"Mmm dd yyyy"
Mmm
represents the month in an abbreviated form (Jan
,Feb
,Mar
,Apr
,May
,Jun
,Jul
,Aug
,Sep
,Oct
,Nov
, orDec
).dd
represents the day. If the day is less than 10, the firstd
is a blank character.yyyy
represents the year.
__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 defined
if the language level is set to
LANGLVL(*ANSI)
. __STDC_VERSION__
- Defined to be an integer constant of type long int. This macro is defined only if __STDC__ is also defined and has the value 199409L. This macro is not defined for C++.
__TIME__
- Defined
as a character string literal containing the time when the source
file was compiled. The time is in the form:
where:"hh:mm:ss"
hh
represents the hour.mm
represents the minutes.ss
represents the seconds.
__cplusplus
- Defined when compiling a C++ program, indicating that the compiler is a C++ compiler. This macro has no trailing underscores. This macro is not defined for C.
Note:
- Predefined macro names cannot be the subject of a
#define
or#undef
preprocessor directive. - 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.
- The value of
__LINE__
changes during compilation as the compiler processes subsequent lines of your source program. - The value of
__FILE__
and__TIME__
changes as the compiler processes any#include
files that are part of your source program. - You can also change
__LINE__
and__FILE__
using the#line
preprocessor directive.
Examples
The following
printf()
statements display the
values of the predefined macros __LINE__
, __FILE__
,
__TIME__
, and __DATE__
and print
a message indicating if the program conforms 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
See the ILE C/C++ Language Reference for additional information on predefined macros.