c++ - How to define a macro in C to obtain the function name through a function
阿神
阿神 2017-07-04 13:45:23
0
1
1420

How to define a macro to obtain the function name string, as follows:

//某一函数
void fun0(){
    ....
}

//宏定义
#define GET_NAME(fun) ....... // 这个怎么写

//获取 name=="fun0"
char *name = GET_NAME(fun0)
阿神
阿神

闭关修行中......

reply all(1)
刘奇

It’s very simple, I’ll give you some black technology:

#define  CLASS_NAME(x)  L#x
#define  METHOD_NAME(x) L#x
#define  LogInfo(str_class,str_method,str_format,...)  \
Log(LogFilter::Info,METHOD_NAME(str_method),CLASS_NAME(str_class), str_format,__VA_ARGS__);

The Log method is defined like this:

void Log(LogFilter filter, wchar_t* classname, wchar_t* methodname, wchar_t* format, ...)
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template