Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top