Tony wrote in message ...
"BobR" wrote in message ...
Pete Becker wrote in message ...
__FILE__ and __LINE__ are always valid, and their meanings are specified
by the C++ standard. If a compiler switch disables them, the compiler
doesn't conform to the language definition when that switch is used.
__FUNCTION__ is not specified by the standard. You'll have to look at
your compiler's documentation to figure out what it does and when it
does it.
If the compiler is C99 complient, you can use '__func__' [1].
[1] - ref: GCC docs. (Some minor restrictions on concatenation.)
A problem with the __func__ and __FILE__ macros is that you can't
control the formatting. Sometimes you may want just a file name rather
than a full path, for example.
std::string FuncName(__func__);
// change 'FuncName' to what you want.
It's odd that the C99 __func__ macro is not __FUNC__, don't ya think?
Tony
If '__func__' was a macro, it might have an all uppercase name.
From GCC docs:
"
__func__ is defined by the ISO standard C99:
The identifier __func__ is 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 the unadorned name of the function.
By this definition, __func__ is a variable, not a string literal. In
particular,
__func__ does not catenate with other string literals.
In C++, __FUNCTION__ and __PRETTY_FUNCTION__ are variables,
declared in the same way as __func__.
"