Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error: variable or field ‘myfunction’ declared void [duplicate]

In the following, I haven't defined the type doesntexist.

void myfunction(doesntexist argument)
{
}

GCC 4.7.2 says "error: variable or field ‘myfunction’ declared void"

My question is this: What's going through the compilers mind here to refer to the function name being void and not the argument type?

[EDIT]
Before downvoting, be aware the answer to this issue is related to the order of the errors and -Wfatal-errors stopping the more immediately relevant message from being printed. This is not simply me having a go at a slightly vague compiler message.

like image 982
jozxyqk Avatar asked Nov 13 '13 08:11

jozxyqk


1 Answers

Thanks, @JoachimPileborg. The unedited error log didn't contain anything useful, and it should have! The comment lead me to the issue and solution... remove -Wfatal-errors from my makefile.

19:17 >>> gcc -Wfatal-errors main.c
main.c:2:17: error: variable or field ‘myfunction’ declared void
compilation terminated due to -Wfatal-errors.

and removing -Wfatal-errors...

19:18 >>> gcc main.c 
main.c:2:17: error: variable or field ‘myfunction’ declared void
main.c:2:17: error: ‘doesntexist’ was not declared in this scope

Problem solved.


For those who say "why use -Wfatal-errors in the first place?": I usually don't want all the errors as the first can trigger the rest. In this case it looks like the errors are given out of order, or at least in an unexpected order - I assume the compiler would run into the ‘doesntexist’ was not declared error first.

like image 79
jozxyqk Avatar answered Nov 15 '22 01:11

jozxyqk