Error: Variable or field "myfunction" declared invalid

Below I have not 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 happens to the compilers here to refer to the function name as empty rather than the type of the argument?

[EDIT]
Before doing downvoting, keep in mind that the answer to this question is related to the order of errors and -Wfatal-errors stopping the printing of a more current message . It's not just that I have an idea with a small vague compiler message.

+6
source share
3 answers

Thanks @JoachimPileborg. An unedited error log does not contain anything useful, and it should have! A comment led me to a problem 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 

The problem is resolved.


For those who say β€œwhy use -Wfatal-errors in the first place?”: I usually don’t want all errors to be the first ones that others can trigger. In this case, it seems that the errors are thrown out of order, or at least in an unexpected order - I assume that the compiler will encounter the error 'doesntexist' was not declared .

+4
source

This is definitely not a problem with the void type function, possibly a g++ compiler with a bad error message scheme when the function parameters consist of an unknown type.

+2
source

Hi @jozxyqk you need to specify the type of the argument, if what you have in Coliru correctly reflects your code, you need to specify a valid data type for the argument, for example void myfunc(string argument) or void myfunc(int argument) and t .d.

In datatypes there is a decent resource here , and another here . It might be worth doing a Google search on how to use data types in C ++ or similar, so yu can find some reading material on them and their use.

The link here is a modified version that shows the string as a valid data type for the argument and the overloaded version for the int argument.

Let me know if you need more information :)

+1
source

Source: https://habr.com/ru/post/957972/


All Articles