liveBook · Manning

__FILE__

As explained in Modern C, Third Edition

__FILE__ is a predefined C macro that expands to a string literal naming the current source file.

__FILE__ is a predefined C macro that expands to a string literal naming the current source file, or translation unit. It is useful when debugging because diagnostic output can identify where it originated. section 17.3

Source location in diagnostic output

A tracing macro can incorporate __FILE__ into formatted debugging output so that each message carries its originating file name. The related __LINE__ macro supplies the line number, while __func__ supplies the current function name. section 17.3

Related predefined context constructs include:

  • __LINE__ expands to an integer constant representing the actual source line. section 17.3
  • __DATE__ and __TIME__ provide the compilation date and time as string literals. section 17.3
  • __func__ provides the name of the current function through a local static variable. section 17.3

How Modern C, Third Edition covers it

How deep it goes
Defines its string-literal expansion and debugging role, but does not develop its implementation mechanics.
Examples
Uses macro-based trace output that reports source location alongside debugging values.
What it assumes
Assumes familiarity with C macros and formatted output while introducing predefined invocation-context constructs.
What you can do after
Diagnose/debug with it by adding the originating source-file name to tracing or diagnostic output.
How it connects
Connects source-file identification with __LINE__, __DATE__, __TIME__, __func__, and fprintf-based tracing.

Also explained in

Compare how 2 books explain __FILE__ →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C, Third Edition. The section links point to the parts of the book it draws on.