My C language teacher claims that all variables must be defined before any operation. I can somehow recall it's a very old feature of C (no later than 1990) but I can't reproduce it with GCC 7.2.0.
My teacher claims this:
int main(){
int a; /* Valid */
a = 1; /* An operation */
int b; /* Invalid because an operation has already occurred */
return 0;
}
I tried compiling with
gcc test.c -std=c89 -Wall -Wextra -pedantic
but it gives no error, not even a warning.
How can I verify (or prove wrong) that statement?
Compile with
-pedantic-errors
, like this:and you should see this error (among the unused variable warnings):
in GCC 7.20.
PS: The comments are invalid too, I removed them before compiling.