Search code examples
cgccfor-loopc99pragma

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


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

Solution

  • 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.