Visual 2015调试器中的C++代码。站台:窗口10
表窗上写着:
NamefunctionPointer Value:0x012812d0 Type:void(*)(float)
NameprintStuff Value:0x01282440 Type:void(float)
Name&printStuff Value:0x01282440 Type:void(*)(float)
但是,输出窗口显示:
functionPointer = 012812D0 printStuff = 0x012812D0 &printStuff = 0x012812D0这是打印填充函数
#include<iostream>
using namespace std;
void printStuff(float)
{
cout << "This is the print stuff function." << endl;
}
const float PI = 3.1415926f;
int main()
{
void(*functionPointer)(float); // *functionPointer is a pointer
functionPointer = printStuff; // *functionPointer point to function printstuff
cout << "functionPointer = " << functionPointer << " " << "printStuff = " << printStuff << " " << "&printStuff = " << &printStuff << endl;
functionPointer(PI);
return 0;
}

输出

发布于 2018-01-29 19:43:55
这种行为似乎是由于增量链接。当启用该函数时,该函数组装在一个内存地址中,而另一个地址包含一个跳转表条目,其中一个跳转指令指向“真实”地址。函数总是通过调用跳转表来调用。如果禁用增量链接,那么跳转表中的“绕行”就会消失,您的示例案例也只显示了一个地址。
其他所有内容似乎都显示了跳转表的地址,但是'printStuff‘和'&printStuff’监视表达式显示了函数代码所在的实际地址。
https://stackoverflow.com/questions/48504008
复制相似问题