before start, sorry for my poor English. Environment: c, c++, VS2019, after C99
Problem: I have to call functions which have named with prefix with callee name. I have many callee and variable prefix, so I want to handle it macro in preprocess-time for convenience with coding.
I tried:
`void prefix_function_name();
void function_name(){
(prefix_##__func__)();
}
`
I know it can't be possible, cause func is const char[].
So I need to : get function name with a token not a string. or : turn a string into a token. ex)
void foo(); const char[] a = "foo";
a();
Is anyone have solution?
Here's my actual problem.
I have many functions with C code. And I'm going to make test code with gtest(C++). And I need to use mock(or stub. anyway) for functions. But, there is no way to call mock function instead of original function. So I need to make hook like this
`extern "C" void mock_foo();
void foo(){
return mock_foo(); // hook
... // actual code
}
`
To avoid miss typing and human error, I wanted to make macro that makes hook for functions. Now I'm using macro like this. (Not in detail)
`#define MACRO(func_name) return mock_##func_name();
void foo(){
MACRO(foo) // hook
... // actual code
}
`
And I wanted to get rid of typing function name.
Here's my actual problem. Is there any way?
(prefix_##__func__)();(assuming it would work) any better thanprefix_function_name()?function_namethe name of the current function is alwaysfunction_nameno macros or runtime effects can change that