在下面的代码片段中,main函数调用foo函数,不带任何参数和括号.奇怪的是,这段代码可以由gcc编译.我实际检查汇编代码,发现编译器只是忽略了这一行.所以我的问题是在哪种情况下使用这种代码?或者gcc的支持只是一个巧合,实际上它完全没用.
int foo(int a,int b)
{
return a+b;
}
int main()
{
foo; // call foo without parameter and parenthesis
return 0;
}
Run Code Online (Sandbox Code Playgroud)
它的汇编代码由objdump -d转储
00000000004004c0 <main>:
4004c0: 55 push %rbp
4004c1: 48 89 e5 mov %rsp,%rbp
4004c4: b8 00 00 00 00 mov $0x0,%eax
4004c9: 5d pop %rbp
4004ca: c3 retq
4004cb: 0f 1f 44 00 00 nopl 0x0(%rax,%rax,1)
Run Code Online (Sandbox Code Playgroud) c ×1