void func() {assert(0);}
int main () {void func();}
The above code does not call func(), or at least does not reach the assertion. Not that I really need to know, but I’m just curious, what is going on here?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You’re declaring a prototype for a function named
funcwhich returns nothing and takes no arguments. That’s (one of) the subtle difference between function calls and function prototypes. Notice that the line abovemain, thevoid func() {assert(0);}, has no effect on whether this is a prototype or a call. You could remove it and the code would do the same thing – that is, nothing.This also tells you that you can redeclare function prototypes. You could even have this:
And the code would still do what it did before – nothing.
If you leave off the
void, it would call the function.Also, notice that in the case of a function which takes parameters, this:
would not turn into a prototype if you added
voidbefore it like this:it would just produce a syntax error.