I am printing out (printf) the name of the function as I enter it by using the "__FUNCTION__" predefined macro (in gcc and clang). However, if I use -Wpedantic, I get this warning:
warning: ISO C does not support ‘__FUNCTION__’ predefined identifier [-Wpedantic]
How do I silence that warning?
Warnings from -pedantic are given where they are required by the base standard. (It would not make sense for such warnings to be given only for features not in the specified GNU C dialect, since by definition the GNU dialects of C include all features the compiler supports with the given option, and there would be nothing to warn about.)
These warnings are made optional because GCC is not smart enough to see all the reasons why the code might be correct despite appearing to have an error. Here is one example of how this can happen: { int x; switch (y) { case 1: x = 1; break; case 2: x = 4; break; case 3: x = 5; } foo (x); }
See Function Attributes . This warning is enabled by -Wall or -Wextra . Warn when a #pragma directive is encountered which is not understood by GCC. If this command line option is used, warnings will even be issued for unknown pragmas in system header files. This is not the case if the warnings were only enabled by the -Wall command line option.
The following language-independent options do not enable specific warnings but control the kinds of diagnostics produced by GCC. Check the code for syntax errors, but don't do anything beyond that. Inhibit all warning messages. Make all warnings into errors. Make the specified warning into an error.
There is no reason to use __FUNCTION__
.
__func__
is the standard one (C99, C11, C17). C11 6.4.2.2p1:
The identifier
__func__
shall be implicitly declared by the translator as if, immediately following the opening brace of each function definition, the declarationstatic const char __func__[] = "function-name";
From GCC documentation:
__FUNCTION__
is another name for__func__
, provided for backward compatibility with old versions of GCC.
And if you want to know how old, __func__
appeared in GCC 2.95, released July 31, 1999. Mind you, you do not need __FUNCTION__
for anything else but to support GCC 2.94 or earlier. If you do, then that warning is probably least of your worries.
However, __func__
isn't available in C89/90 mode either, so you'd get a warning there. If you care about ISO diagnostics, then you need to use a more recent revision. Modern GCCs default to GNU C11 or C17 already.
See also: What's the difference between __PRETTY_FUNCTION__
, __FUNCTION__
, __func__
The standard compliant function identifier is __func__
From §6.4.2.2 of the C11 specification
The identifier
__func__
shall be implicitly declared by the translator as if, immediately following the opening brace of each function definition, the declarationstatic const char __func__[] = "function-name";
appeared, where function-name is the name of the lexically-enclosing function.
I believe that __func__
was added in C99.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With