PATH
Several standard macros are predefined, some by ANSI C and some as extensions. Their names all start and end with double underscores.
The following predefined macros are part of the ANSI C standard:
__FILE__
This macro expands to the name of the current input file, in the form of a C string constant.
__LINE__
This macro expands to the current input line number, in the form of a decimal integer constant. (Note that although this is considered a predefined macro, its definition changes with each new line of source code.)
This and __FILE__ are useful in generating an error message to report an inconsistency detected by the program; the message can state the source line at which the inconsistency was detected. For example:
fprintf (stderr,
"Internal error: negative string length "
"%d at %s, line %d."
length, __FILE__, __LINE__);
An #include command changes the expansions of __FILE__ and __LINE__ to correspond to the included file. At the end of that file, when processing resumes on the input file that contained the #include command, the expansions of __FILE__ and __LINE__ revert to the values they had before the #include (but __LINE__ is then incremented by one as processing moves to the line after the #include ).
The expansions of both __FILE__ and __LINE__ are altered if a #line command is used. See the section " See Combining Source Files ."
__DATE__
This macro expands to a string constant that describes the date on which the preprocessor is being run. The string constant contains 15 characters and looks like "Tue Jun 02 1992".
The following predefined macros are GNU C extensions to the ANSI C standard:
__GNUC__
This macro is defined if and only if this is GNU C. Moreover, it's defined only when the entire GNU C compiler is in use; if you invoke the preprocessor directly, __GNUC__ is undefined.
__STRICT_ANSI__
This macro is defined if and only if the -ansi switch was specified when GNU C was invoked. Its definition is the null string. This macro exists primarily to direct certain GNU header files not to define traditional UNIX constructs that are incompatible with ANSI C.
__GNUG__
The GNU C compiler defines this when the compilation language is C++; use __GNUG__ or __cplusplus to distinguish between GNU C and GNU C++ code.
__cplusplus
The draft standard for C++ requires the predefinition of this variable. GNU C++ to define it as 1 , to indicate that this compiler does not yet fully support the standard C++ language. You can use __cplusplus to test whether a header is compiled by a C compiler or a C++ compiler.
__VERSION__
This macro expands to a string describing the version number of the compiler. The string is normally a sequence of decimal numbers separated by periods, such as "1.18" . The main use of this macro is to incorporate the version number into a string constant.
__OPTIMIZE__
This macro is defined in optimizing compilations. It causes certain GNU header files to define alternative macro definitions for some system library functions. It's unwise to refer to or test the definition of this macro unless you make sure that programs will execute with the same effect regardless.
__CHAR_UNSIGNED__
This macro is defined if and only if the data type char is unsigned on the target machine. Its purpose is to cause the standard header file limit.h to work correctly. It's bad practice to refer to this macro yourself; instead, refer to the standard macros defined in limit.h .
The following macros are defined in Mac OS X:
__OBJC__
This macro is defined when you compile Objective-C ".m" files or Objective-C++ ".M" files, or when you override the file extension with -ObjC or -ObjC++ .
__NATURAL_ALIGNMENT__
This macro is defined on systems that use natural alignment. When using natural alignment, an int is aligned on sizeof(int) boundary, a short int is aligned on sizeof(short) boundary, and so on. It's defined by default when you're compiling code for the PowerPC, SPARC, and HPPA. It's not defined when you use the -malign-mac68k compiler switch.
The following code snippet guarantees that the struct layout for foo will not change regardless of whether or not __NATURAL_ALIGNMENT__ is defined.
struct foo {
short count;
#ifdef __NATURAL_ALIGNMENT__
/* compiler will pad to align "flags"
on the sizeof(long) boundary */
#else
unsigned char pad[ sizeof(long) - sizeof(short) ];
#endif
long flags;
}