five minutes ago I did something I never did before (it's not about sex...) look at the code :
// g++ DeathToAllButMetal.cc
#include<iostream>
void DeathToAllButMetal(){
std::cout << "A MASTERPIECE MADE BY STEEL PANTHER" << std::endl;
}
int main(){
DeathToAllButMetal();
DeathToAllButMetal;
return 0;
}
you see I forgot the "()" at the second DeathToAllButMetal
surprisingly the compiler doesn't yell on me. So for the compiler this line of code means something, but what ? because at the running, the method is not called... It's look to be a basic question, but I don't remember having saw this in the past.
It's just a no-op. The name of a function decays into a pointer to that function in that context, but since you don't do anything with it, nothing happens. If you turn up your warnings level you may get a message along the lines of "statement has no effect". For example, clang++ says (even with no flags):
example.cpp:11:3: warning: expression result unused [-Wunused-value]
DeathToAllButMetal;
^~~~~~~~~~~~~~~~~~
1 warning generated.
G++ warned too, but I needed to add -Wall
:
example.cpp: In function ‘int main()’:
example.cpp:11: warning: statement is a reference, not call, to function ‘DeathToAllButMetal’
example.cpp:11: warning: statement has no effect
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With