Why can't I use for(int i = 0; i < 10; i++) ?
Bean
Posts: 8,129
When I try to declare a variable inside a "for" statement I get an error
test.c:12:3: error: 'for' loop initial declarations are only allowed in C99 mode
How do I enable C99 mode ?
Bean
test.c:12:3: error: 'for' loop initial declarations are only allowed in C99 mode
How do I enable C99 mode ?
Bean
Comments
The above compiles and runs, if you uncomment the bottom printf you will get a compile error.
- '//' , aka C++ comments isn't allowed in ANSI (although it is in C99. Personally I find them unreadable)
- 'main' shall be 'int', not 'void', so you should use 'int main(void)' (on some architectures it _does_ make a difference - the exit handling doesn't work correctly unless main is 'int').
- Due to the above there needs to be a 'return (0);' at the end.
-Tor
GCC can be used with strict c89 mode for folks who need it.
$ propeller-elf-gcc -pedantic -std=c89 foo.c