I have many different functions, and they all have simple printf
statements using __func__
similar to this one:
printf("%s - hello world!", __func__);
Now the problem I am running into is that in some functions it returns <unknown>
instead of the function name.
Why is that? Am I doing something wrong? AFAIK __func__
is a part of c99
so I don't understand why it isn't working as advertised.
I am using GCC 4.7.2 in Debian.
In C there are no subroutines, only functions, but functions are not required to return a value. The correct way to indicate that a function does not return a value is to use the return type "void". ( This is a way of explicitly saying that the function returns nothing. )
Predefined Identifier __func__ in C Identifier is the name given to an entity in programming to identify it in the program. Generally, identifiers are created by the programmer for efficient working but there are some predefined identifiers that are inbuilt in programming. For example, cout, cin, etc.
In C, use void no_args(void) to declare a function that truly takes no parameters (and returns nothing).
Preprocessor statements don't need a semicolon at the end. If you put one, the preprocessor actually thinks you mean it with a semicolon. If you are confused with #define s for constants, const int would probably be easier to comprehend.
It sounds like a header you are including must be doing something similar to this bug and defining __func__
as follows:
define __func__ "<unknown>"
and so you only see it when you include that header(s). A quick way to test for this would be to use __FUNCTION__
in a section of the code where __func__
does not work. Then you need to narrow it down and figure out which header has the troublesome logic and fix it.
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