Of course it's in a different section: it's not (and cannot be) a
preprocessor feature. There is no way to detect a function name during
translation phases 1 to 4, which constitute the preprocessing stage.
I didn't say I was necessarily using my head when scanning the list of
preprocessor macro names looking for something resembling the word
"function"....
The lower case spelling of the identifier is another clue that we're
not dealing with a macro.
.... a clue I wasn't privy to before I'd ever seen its spelling.
But the most annoying thing is that it's not a C89 feature, yet a
conforming C89 implementation can provide it, since the name is in the
implementation name space. And C99 implementations are few and far
between, so portable C code doesn't have much use for __func__.
If one does happen to have a compiler that supports __func__, and wants to
use it while developing portable code, it shouldn't be too difficult to
wrap it up with the help of the preprocessor in order to selectively
disable it on other platforms. If there isn't a way to detect __func__
support automatically, then in the worst case the compiles would take a
-DFUNC_SUPPORTED (or whatever) as required, e.g.:
/*
* Portable use (or non-use) of __func__ in debug mode
*/
#include <stdio.h>
//#define FUNC_SUPPORTED
//#define NDEBUG
#ifdef FUNC_SUPPORTED
#define FUNC __func__
#else
#define FUNC ""
#endif
#ifdef NDEBUG
#define diagnose(file, line, func) ((void)0)
#else
void diagnose(const char *file, int line, const char *func)
{
printf("FILE: %s, LINE: %d", file, line);
if (*func)
printf(", Func: %s", func);
printf("\n\n");
}
#endif
int main()
{
printf("Hello, world\n");
diagnose(__FILE__, __LINE__, FUNC);
diagnose(__FILE__, __LINE__, FUNC);
diagnose(__FILE__, __LINE__, FUNC);
printf("Goodbye, world\n");
return 0;
}
-leor