CITS2002 Systems Programming  
prev
next CITS2002 CITS2002 schedule  

Pre-defined preprocessor tokens

The recent examples enabling detection of C language standard and operating system platform, are a small, but important sample of the information available when compiling programs.

We can see the pre-processor's pre-defined tokens with:

prompt> cc -dM -E - < /dev/null
(133 lines on MacOS, 385 on Ubuntu/Linux ...)


Some of the following examples (not specifically related to portability) taken from: gcc's Standard Predefined Macros

The standard predefined macros are specified by the relevant language standards, so they are available with all compilers that implement those standards.

__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.

__FILE__ and __LINE__ are useful in generating an error message to report an inconsistency detected by the program. C99 also introduced __func__, and GCC has provided __FUNCTION__ for a long time.


__STDC__

In normal operation, this macro expands to the constant 1, to signify that this compiler conforms to ISO Standard C.

__STDC_VERSION__

This macro expands to the C Standard’s version number, a long integer constant of the form yyyymmL where yyyy and mm are the year and month of the Standard version.

__STDC_HOSTED__

This macro is defined, with value 1, if the compiler’s target is a hosted environment. A hosted environment has the complete facilities of the standard C library available.

 


CITS2002 Systems Programming, Lecture 22, p4, 16th October 2023.