g++ __FUNCTION__ replace time

后端 未结 7 703
迷失自我
迷失自我 2020-12-20 17:16

Can anyone tell when g++ replaces the __FUNCTION__ \'macro\' with the string containing the function name? It seems it can replace it not until it has check the

相关标签:
7条回答
  • 2020-12-20 17:49

    Is there any way to force that replacement with a string to an earlier step so that the line is correct?

    No. __FUNCTION__ (and its standardized counterpart, __func__) are compiler constructs. __FILE__ and __LINE__ on the other hand, are preprocessor constructs. There is no way to make __FUNCTION__ a preprocessor construct because the preprocessor has no knowledge of the C++ language. When a source file is being preprocessed, the preprocessor has absolutely no idea about which function it is looking at because it doesn't even have a concept of functions.

    On the other hand, the preprocessor does know which file it is working on, and it also knows which line of the file it is looking at, so it is able to handle __FILE__ and __LINE__.

    This is why __func__ is defined as being equivalent to a static local variable (i.e. a compiler construct); only the compiler can provide this functionality.

    0 讨论(0)
提交回复
热议问题