Predefined Macros for function name __func__

后端 未结 4 2079
长发绾君心
长发绾君心 2020-12-29 03:54

I am attempting to build a debug log message function that records the file, line, and function of of where the log message was called from.

#define DEBUG_P         


        
4条回答
  •  佛祖请我去吃肉
    2020-12-29 04:18

    You're assuming __func__ is a macro, but it's not. It's a conditionally-supported predefined identifier, so you can't check it with #if defined or #ifdef.

    If the compilers have no way of telling you whether this is supported (they could via a _FUNC_SUPPORTED or something, I'm not saying they actually are doing this), you'll have to check the compiler instead of the actual identifier.

    Something along the lines:

    #ifndef __FUNCTION_NAME__
        #ifdef WIN32   //WINDOWS
            #define __FUNCTION_NAME__   __FUNCTION__  
        #else          //*NIX
            #define __FUNCTION_NAME__   __func__ 
        #endif
    #endif
    

提交回复
热议问题