C/C++ Programmer's Guide (G06.25+)
Preprocessor Directives and Macros
HP C/C++ Programmer’s Guide for NonStop Servers—429301-002
12-11
Predefined Macros
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, Predefined Macros. 
Note that the identifiers for these macros begin and end with two underscores.
None of these predefined macros can be removed using #undef.
The following example demonstrates the use of the __FUNCTION__ macro:
#include <stdio.h>
char ch[] = __FUNCTION__;
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.










