1) "macros" like __FILE__
and __LINE__
are expanded by the compilation system's "preprocessor".. The source text is modified before the compiler itself actually sees it.
2) This is true of build-in macros like "__LINE__
". It's equally true for any macro you create, with the #define statement.
3) Things like "line numbers" and "function names" are important to debuggers. Debug information is generated by the compiler itself (not the preprocessor). It's related to - but different from - either macro expansion or assembly code generation.
Debug information is usually saved directly in your executable file (along with assembler instructions, string literals, etc) as "metadata".
You can read more here: "How Debuggers Work"
ADDENDUM:
Like debugger metadata (above), func is similar - but different.
From the C99 standard:
6.4.2.2 Predefined identifiers
Semantics:
The identifier __func_ _ shall be implicitly declared by the translator as if, immediately following the opening brace of each function definition, the declaration
static const char __func__[] = "function-name";
appeared, where function-name is the name of the lexically-enclosing function.
This name is encoded as if the implicit declaration had been written in the source character set and then translated into the execution character set as indicated in translation phase 5.
EXAMPLE
Consider the code fragment
#include <stdio.h>
void myfunc(void) {
printf("%s\n", __func__);
/* ... */
}
Each time the function is called, it will print to the standard output stream:
myfunc
You'll also see __FUNCTION__
in many C compilers, but it was never standard.
You can read more here:
__FILE__, __LINE__, and __FUNCTION__ usage in C++