The compiler predefines several macros. __LINE__ and __FILE__ give the current line and file, __DATE__ and __TIME__ give the build date and time, __STDC__ is 1 for a conforming compiler, and __STDC_VERSION__ identifies the standard (199901L, 201112L, 201710L). __func__ (C99) is a predefined identifier for the current function name.
Remember
__FILE__ /* "main.c" */
__LINE__ /* current line number */
__DATE__ /* "Nov 27 2026" */
__STDC_VERSION__ /* 201112L for C11 */
__func__ /* current function name */
Reference
Cheat Sheet
Keep these facts handy while you work with Predefined Macros in C.
Topic
Detail
Location
__FILE__, __LINE__, __func__
Build time
__DATE__, __TIME__
Standard
__STDC__, __STDC_VERSION__
Use
Logging and assertions
Code
C Examples
Compile each example with gcc file.c -std=c11 -Wall -o out. Next: #error and #pragma.
Example 1 — Line number and standard version
Compile with -std=c11; the __LINE__ result depends on the line the macro appears on (line 4 here).
__LINE__ expands to the line number where it is written.
__STDC__ is 1 on conforming compilers.
-std=c11 selects 201112L; -std=c17 would print 201710.
Edge Cases & Pitfalls
Check these before relying on Predefined Macros in real programs.
date
Non-reproducible builds
__DATE__ and __TIME__ change on every build, which breaks reproducible binaries.
std
__STDC_VERSION__ missing in C89
It is undefined in C89, so test defined(__STDC_VERSION__) first.
Remember
Key Takeaways
Logging: file and line.
Standard: check the version.
Builds: avoid date macros for reproducibility.
One line: The compiler predefines several macros.
Frequently Asked Questions
It expands to the current source line number as an integer constant, handy for log messages and assertions.
__func__ is a predefined variable (C99) holding the name of the current function as a string.
Continue with "C #error and #pragma" next. Stop the build with #error and give compiler hints with #pragma. The C Preprocessor hub lists every topic in order.