I've got a very big program which compiles with gcc without warnings.
If I turn on c99 mode --std=c99 on the command line, it gives a huge number of warnings and errors.
But I love the idiom for(int i=0; i<20; i++){ code }
in place of {int i; for (i=0; i<20; i++){ code }}
Is there any way to tell gcc to allow this and only this?
Alternatively, is there any way to enable c99 mode in the particular functions I'm working on? Something like
#pragma c99 on
for(int i=0; i<99; i++)
{
code
}
#pragma c99 off
This happens because declaring variables inside a for loop wasn't valid C until C99(which is the standard of C published in 1999), you can either declare your counter outside the for as pointed out by others or use the -std=c99 flag to tell the compiler explicitly that you're using this standard and it should interpret ...
C99 (previously known as C9X) is an informal name for ISO/IEC 9899:1999, a past version of the C programming language standard.
very simple. In the project properties (right click over project->properties) click "Project's build options..." button, then in "Compiler settings" tab, click in "Other options" sub-tab. Type "-std=c99" in text area and thats all. cheers!!.
It is likely that the warnings and errors are because -std=c99
requests standard-conforming C99, which means that many platform-specific functions that pollute the C99 namespace are not defined.
Instead, you should try --std=gnu99
, which is the C99-equivalent to the default mode of gnu89
.
Alternatively to use -std=gnu99 you can disable individual warnings:
-Wno-declaration-after-statement
Read info gcc:
`-Wdeclaration-after-statement (C and Objective-C only)' Warn when a declaration is found after a statement in a block. This construct, known from C++, was introduced with ISO C99 and is by default allowed in GCC. It is not supported by ISO C90 and was not supported by GCC versions before GCC 3.0. *Note Mixed Declarations::.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With