In the following code snippet, the main function calls foo function without any parameter and parenthesis. It is strange that this code can be compiled by gcc. I actually ch
This is no different than having any other type of expression and ignoring its value, like:
int main(void)
{
42;
return 0;
}
there's nothing special, this is not calling the function since the function-call operators ()
are not being used. All you're doing is "computing" the functions' address, then ignoring it.
foo
is not getting called, it is just referred (and not assigned to anything).
The expression foo
is evaluated (giving the address of the function), and the result is discarded. Without the ()
operator, the function isn't called.