是否有一个宏技巧可以在不影响函数定义的情况下只重命名函数调用,特别是对于 gcc/cpp:
#define get_resolution __mock_get_resolution
上面的宏改变了所有地方,但我只是想让这个对函数调用get_resolution();
生效,而不影响定义void get_resolution()
void get_resolution()
{
}
void display()
{
get_resolution();
}
最佳答案
作为特定于 gcc 的解决方案,
The `alias' attribute causes the declaration to be emitted as an
alias for another symbol, which must be specified. For instance,
void __f () { /* Do something. */; }
void f () __attribute__ ((weak, alias ("__f")));
关于用于选择性替换的 C 宏技巧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11762529/