c - Can't define variables after any operation? -
this question has answer here:
- variable declaration placement in c 6 answers
my c language teacher claims all variables must defined before operation. can somehow recall it's old feature of c (no later 1990) can't reproduce gcc 7.2.0.
my teacher claims this:
int main(){ int a; /* valid */ = 1; /* operation */ int b; /* invalid because operation has occurred */ return 0; }
i tried compiling with
gcc test.c -std=c89 -wall -wextra -pedantic
but gives no error, not warning.
how can verify (or prove wrong) statement?
compile -pedantic-errors
, this:
gcc test.c -std=c89 -wall -wextra -pedantic-errors
and should see error (among unused variable warnings):
test.c:4:5: error: iso c90 forbids mixed declarations , code [-wdeclaration-after-statement] int b; ^~~
in gcc 7.20.
ps: comments invalid too, removed them before compiling.
Comments
Post a Comment