Re: How to enforce C89-style variable declarations in gcc ?
Re: How to enforce C89-style variable declarations in gcc ?
- Subject: Re: How to enforce C89-style variable declarations in gcc ?
- From: Paul Russell <email@hidden>
- Date: Wed, 23 Jun 2010 15:06:12 +0100
On 23 Jun 2010, at 14:55, Peter O'Gorman wrote:
> On 06/23/2010 02:52 AM, Paul Russell wrote:
>> I work on a code base which is mostly C with a little C++, and is
>> mostly built with gcc (Mac OS X and Linux) but occasionally it needs
>> to be built with MSVC. Microsoft's C compiler is still pretty much
>> C89 with a few minor extensions, and it still doesn't support mixed
>> code and variable definitions à la C++/C99. So I need to find a way
>> to prevent developers from writing out-of-order code/variable
>> definitions while they are working with gcc, otherwise the build
>> subsequently breaks on WIN32. If I use gcc -std=c89 then everything
>> breaks because C++-style comments are not allowed (there may be other
>> issues too, but I haven't looked into this any further). If I use gcc
>> -std=gnu89 then the out-of-order code/variable definitions are
>> allowed, so that doesn't help me either. Any ideas ? I guess I just
>> need something like gcc -std=c99 -fno-inline-variable-definitions, if
>> such an option existed.
>>
>
> -Wdeclaration-after-statement (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.
>
Thanks - that at least generates a warning. It appears that from gcc 4.4 onwards I can use -Werror=declaration-after-statement to get an error rather than a warning, but this is broken in gcc 4.2 and unsupported in gcc 4.0.
Paul
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden