开发者

Get function name as symbol (not as string) - C preprocessor

开发者 https://www.devze.com 2023-04-08 02:34 出处:网络
Is there a way in C to ge开发者_如何学JAVAt the function name on which I can use token-pasting (I know __FUNCTION__ and __func__, but they don\'t expand to name at pre-processing,

Is there a way in C to ge开发者_如何学JAVAt the function name on which I can use token-pasting (I know __FUNCTION__ and __func__, but they don't expand to name at pre-processing, and I do not want the name as a string).

I want to be able to do something like: prefix_ ## __func_name__ , so that, in a function by name func1(), I can access the symbol prefix_func1

(maybe I can still use string, and then use dlsym, but want to know if there are simpler alternatives in GCC, not worrying about portability).


You could make the function identifier a macro, as in

#define FUNC1 func1

void FUNC1(void)
{
   ...
}

and then use FUNC1 for token pasting.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号