我试图在C中覆盖一个函数调用,但是当在同一个编译单元中使用该函数时,我遇到了问题.在下面的代码中,我试图替换函数get_resolution(),但我只能在test.c中完成但不能从display.c中实现它.
// display.c -------------------------------------------------------------
#include <stdio.h>
void get_resolution()
{
printf("Original get_resolution\n");
}
void display()
{
get_resolution();
}
// test.c ----------------------------------------------------------------
#include <stdio.h>
void __wrap_get_resolution()
{
printf("Mock get_resolution\n");
// __real_get_resolution(); // Should be possible to call original
}
int main()
{
display(); // **ISSUE** Original get_resolution() is called
get_resolution(); // __wrap_get_resolution() is called
return 0;
}
// gcc -Wl,--wrap,get_resolution display.c test.c
Run Code Online (Sandbox Code Playgroud)
我的要求是,当我从main()调用display()时,我希望执行__wrap_get_resolution(),但我总是看到正在调用原始的get_resolution().对拆卸的一点分析表明函数get_resolution被不同地调用:
在display() - > get_resolution()的地址已经解析
00000000 <_get_resolution>:
0: 55 push %ebp
1: 89 e5 mov %esp,%ebp
3: 83 …Run Code Online (Sandbox Code Playgroud) C#是否有可能优化以下代码块?
if (specField == null || AddSystemType(specField, layout)
|| AddEnumType(specField, layout)
|| AddUserType(specField, layout))
{
}
Run Code Online (Sandbox Code Playgroud) 我不明白为什么go开发人员选择了类似于func (t Type) MethodName()方法的语法.我无法消化这一事实,特别是在阅读本文并考虑到go是极简主义的事实之后.岂不更简单的语法像func Type.MethodName()或func Type::MethodName()已经足够与物体使用隐含参数像访问this或self.或者我错过了当前语法提供的任何优势?