C/C++ Programmer's Guide (G06.27+, H06.03+)

Table Of Contents
Preprocessor Directives and Macros
HP C/C++ Programmer’s Guide for NonStop Systems429301-010
12-11
Predefined Macros
Usage Guideline
Once you have deleted a macro definition, its identifier no longer exists as a macro
name. Consequently, the #ifdef and #ifndef directives will find the identifier to be
undefined.
Example
To delete the macro definition with identifier red and print “Red is undefined.”:
#define red 1
/* ... */
#undef red
#ifdef red
printf("Red is defined.\n");
#else
printf("Red is undefined.\n");
#endif
Predefined Macros
The compiler provides six predefined object-like macros. These macros expand to
various statistics regarding compilation, as shown in Table 12-2. Note that the
identifiers for these macros begin and end with two underscores.
Table 12-2. Predefined Macros
Macro What It Expands To
__DATE__ A string literal representing the date of compilation. This string has the
form Mmm dd yyyy, where the first character of the day (dd) is a blank if
the day is less than 10.
__FILE__ A string literal representing the name of the current source file. The
file name is qualified up to the volume (or device) name if the file is on
the same system as the compiler; otherwise, the file name is qualified up
to the system name.
__FUNCTION__
A string representing the name of the current function, or an empty string
if it appears outside of a function. This macro cannot be redefined.
__LINE__ A long value representing the current line number in the current source
file. If the current source file is an EDIT file, this value is equal to the
EDIT line number multiplied by 1000. For any other type of source file,
this value is equal to the ordinal value of the line multiplied by 1000.
__STDC__ A long value signifying that the compiler is to comply with the ISO/ANSI
C standard. If the value is 1, the compiler complies with the standard.
__TIME__ A string literal representing the time of compilation. This string has the
form hh:mm:ss, where the hour (hh) ranges from 0 to 23. The time
zone is that of the system on which the compilation takes place.