Is there any way to enable for (int i = 0; ... in gcc without having to enable c99 mode

I have a very large program that compiles with gcc without warning.

If I turn on c99 --std = c99 mode on the command line, it will give a huge amount of warnings and errors.

But I love the idiom for(int i=0; i<20; i++){ code }

instead of {int i; for (i=0; i<20; i++){ code }} {int i; for (i=0; i<20; i++){ code }}

Is there a way to tell gcc to resolve this and only that?

Alternatively, is there a way to enable c99 mode in the specific functions I'm working on? Something like

 #pragma c99 on for(int i=0; i<99; i++) { code } #pragma c99 off 
+7
source share
2 answers

It is likely that warnings and errors are related to the fact that -std=c99 requests a standard compatible C99, which means that many platform-specific functions that pollute the C99 namespace are undefined.

Instead, you should try --std=gnu99 , which is the equivalent of C99 for the default mode of gnu89 .

+7
source

As an alternative to using -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 ::.
+2
source

All Articles