Menu

File macro

Cyder

File macro

The c11 standard describes a macro called __FILE__, that always expands to a string constant for the file name.
It is a predefined macro, that cannot be undefined or redefined.

Hint: __FILE__ is returned as a normal string token, thus allowing it to be used for string concantation.

// Print the current source file
printf("File = %s\n",__FILE__);

#undef __FILE__ // Can't undef __FILE__
#ifdef __FILE__
// This block will still be enabled
#endif

s.a. [Conditional directives]
s.a. [Macros]


Related

Wiki: Base file macro
Wiki: Line directive

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.