Predefined Macros
suggest changeA predefined macro is a macro that is already understood by the C pre processor without the program needing to define it. Examples include
Mandatory Pre-Defined Macros
__FILE__, which gives the file name of the current source file (a string literal),__LINE__for the current line number (an integer constant),__DATE__for the compilation date (a string literal),__TIME__for the compilation time (a string literal).
There’s also a related predefined identifier, __func__ (ISO/IEC 9899:2011 §6.4.2.2), which is not a macro:
The identifier __func__ shall be implicitly declared by the translator as if, immediately following the opening brace of each function definition, the declaration:
static const char __func__[] = "function-name";
appeared, where function-name is the name of the lexically-enclosing function.
__FILE__, __LINE__ and __func__ are especially useful for debugging purposes. For example:
fprintf(stderr, "%s: %s: %d: Denominator is 0", __FILE__, __func__, __LINE__);
Pre-C99 compilers, may or may not support __func__ or may have a macro that acts the same that is named differently. For example, gcc used __FUNCTION__ in C89 mode.
The below macros allow to ask for detail on the implementation:
__STDC_VERSION__The version of the C Standard implemented. This is a constant integer using the formatyyyymmL(the value201112Lfor C11, the value199901Lfor C99; it wasn’t defined for C89/C90)__STDC_HOSTED__1if it’s a hosted implementation, else0.__STDC__If1, the implementation conforms to the C Standard.
Other Pre-Defined Macros (non mandatory)
ISO/IEC 9899:2011 §6.10.9.2 Environment macros:
__STDC_ISO_10646__An integer constant of the formyyyymmL(for example, 199712L). If this symbol is defined, then every character in the Unicode required set, when stored in an object of typewchar_t, has the same value as the short identifier of that character. The Unicode required set consists of all the characters that are defined by ISO/IEC 10646, along with all amendments and technical corrigenda, as of the specified year and month. If some other encoding is used, the macro shall not be defined and the actual encoding used is implementation-defined.__STDC_MB_MIGHT_NEQ_WC__The integer constant 1, intended to indicate that, in the encoding forwchar_t, a member of the basic character set need not have a code value equal to its value when used as the lone character in an integer character constant.__STDC_UTF_16__The integer constant 1, intended to indicate that values of typechar16_tare UTF−16 encoded. If some other encoding is used, the macro shall not be defined and the actual encoding used is implementation-defined.__STDC_UTF_32__The integer constant 1, intended to indicate that values of typechar32_tare UTF−32 encoded. If some other encoding is used, the macro shall not be defined and the actual encoding used is implementation-defined.
ISO/IEC 9899:2011 §6.10.8.3 Conditional feature macros
__STDC_ANALYZABLE__The integer constant 1, intended to indicate conformance to the specifications in annex L (Analyzability).__STDC_IEC_559__The integer constant 1, intended to indicate conformance to the specifications in annex F (IEC 60559 floating-point arithmetic).__STDC_IEC_559_COMPLEX__The integer constant 1, intended to indicate adherence to the specifications in annex G (IEC 60559 compatible complex arithmetic).__STDC_LIB_EXT1__The integer constant201112L, intended to indicate support for the extensions defined in annex K (Bounds-checking interfaces).__STDC_NO_ATOMICS__The integer constant 1, intended to indicate that the implementation does not support atomic types (including the_Atomictype qualifier) and the<stdatomic.h>header.__STDC_NO_COMPLEX__The integer constant 1, intended to indicate that the implementation does not support complex types or the<complex.h>header.__STDC_NO_THREADS__The integer constant 1, intended to indicate that the implementation does not support the<threads.h>header.__STDC_NO_VLA__The integer constant 1, intended to indicate that the implementation does not support variable length arrays or variably modified types.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents