C Predefined Macros

Intermediate
6 min read
Updated: Nov 2026
1 example

What Is Predefined Macros?

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 */

Cheat Sheet

Keep these facts handy while you work with Predefined Macros in C.

TopicDetail
Location__FILE__, __LINE__, __func__
Build time__DATE__, __TIME__
Standard__STDC__, __STDC_VERSION__
UseLogging and assertions

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

C
#include <stdio.h>

int main(void) {
    printf("line %d\n", __LINE__);
    printf("__STDC__ = %d\n", __STDC__);
    printf("__STDC_VERSION__ = %ld\n", (long)__STDC_VERSION__);
    return 0;
}

How It Works

  1. __LINE__ expands to the line number where it is written.
  2. __STDC__ is 1 on conforming compilers.
  3. -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.

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.

Next: #error and #pragma

Stop the build with #error and give compiler hints with #pragma.

Continue →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful