Why does __func__ return <unknown> in some functions in C?

I have many different functions, and they all have simple printf expressions using __func__ , similar to this:

printf("%s - hello world!", __func__);

Now the problem I am facing is that in some functions it returns <unknown> instead of the function name.

Why? Am I doing something wrong? AFAIK __func__ is part of c99 , so I do not understand why it does not work as advertised.

I am using GCC 4.7.2 on Debian.

+6
source share
1 answer

Sounds like the title you include should do something similar to this bug and define __func__ as follows:

 define __func__ "<unknown>" 

and therefore you only see this when you include this header. A quick way to check this is to use __FUNCTION__ in the code section where __func__ does not work. Then you need to narrow it down and find out which header has complex logic and fix it.

+2
source

Source: https://habr.com/ru/post/950902/


All Articles