Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt

Use this file to discover all available pages before exploring further.

Predefined macros are identifier constants automatically defined by the C preprocessor prior to the compilation phase. They provide metadata about the compilation environment, the current source file, and compiler compliance. The preprocessor substitutes these identifiers with specific string literals or integer constants during translation phase 4. By ISO C standard mandate, these macros are reserved. They cannot be undefined using #undef or redefined using #define.

Standard Predefined Macros (C89/C90)

The following macros are universally supported by any standard-compliant C compiler:
  • __FILE__: Expands to a character string literal representing the presumed name of the current source file.
  • __LINE__: Expands to a decimal integer constant representing the presumed current line number within the current source file.
  • __DATE__: Expands to a character string literal representing the date of translation. The format is "Mmm dd yyyy" (e.g., "Jan 01 2024"). If the day is less than 10, the first character of dd is a space.
  • __TIME__: Expands to a character string literal representing the time of translation. The format is "hh:mm:ss".
  • __STDC__: Expands to the integer constant 1 if the compiler implementation conforms to the ISO C standard.

Extended Standard Macros (C99 and Later)

Subsequent revisions of the C standard introduced additional predefined macros to expose environment and version details:
  • __STDC_VERSION__: Expands to a long integer constant indicating the specific ISO C standard version the compiler adheres to.
    • 199409L (C89 amendment 1)
    • 199901L (C99)
    • 201112L (C11)
    • 201710L (C18)
  • __STDC_HOSTED__: Expands to the integer constant 1 if the implementation is a hosted environment (has the full standard library available), or 0 if it is a freestanding environment.

Syntax and Expansion Visualization

#include <stdio.h>

int main(void) {
    /* String literal expansions */
    const char* current_file = __FILE__;
    const char* compile_date = __DATE__;
    const char* compile_time = __TIME__;

    /* Integer constant expansions */
    int current_line         = __LINE__;
    int is_standard_c        = __STDC__;
    long c_version           = __STDC_VERSION__;
    int is_hosted            = __STDC_HOSTED__;

    return 0;
}

The #line Directive Interaction

While predefined macros cannot be redefined via #define, the preprocessor’s internal state for __LINE__ and __FILE__ can be explicitly mutated using the #line directive.
#line 100 "virtual_file.c"
/* On the next line, __LINE__ expands to 100 and __FILE__ expands to "virtual_file.c" */

Note on __func__

Introduced in C99, __func__ is frequently associated with predefined macros, but it is technically a predefined identifier, not a preprocessor macro. It is evaluated by the compiler, not the preprocessor. It behaves as if the following declaration were implicitly made immediately after the opening brace of a function:
static const char __func__[] = "function_name";
Master C with Deep Grasping Methodology!Learn More