c - Can't define variables after any operation? -


this question has answer here:

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

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -