[ovs-dev] [PATCH 1/5] CodingStyle: Allow C99 mixing of declarations and code.

Jarno Rajahalme jrajahalme at nicira.com
Wed May 28 23:52:59 UTC 2014


On May 28, 2014, at 4:00 PM, Ethan Jackson <ethan at nicira.com> wrote:

> FWIW I'd prefer we don't mix declarations and code unless there's a
> clear reason to do it from a simplicity perspective.  I.E. I think we
> should go from mandating that it's never allowed, to suggesting that
> it's discouraged.  The reason is that most of the code doesn't do
> these things, and there's a value in consistency.  That said, I don't
> feel strongly about it.
> 

Does this cut it for you:

C DIALECT

  Most C99 features are OK because they are widely implemented:
(snip)

    * Mixing of declarations and code within a block.  Please use this
      judiciously; keep declarations nicely grouped together in the
      beginning of a block if possible.

  Jarno

> Ethan
> 
> On Wed, May 28, 2014 at 3:31 PM, Ben Pfaff <blp at nicira.com> wrote:
>> On Wed, May 28, 2014 at 03:31:03PM -0700, Jarno Rajahalme wrote:
>>> 
>>> On May 23, 2014, at 10:04 AM, Ben Pfaff <blp at nicira.com> wrote:
>>> 
>>>> On Thu, May 22, 2014 at 05:37:38PM -0700, Jarno Rajahalme wrote:
>>>>> As even the MSVC 2013 now supports the C99 mixing of declarations and
>>>>> code, we can now allow them in OVS code.
>>>>> 
>>>>> GCC (at least some versions of it) require the -std=c99 option to not
>>>>> issue warnings, and since we rely in GCC extensions when compiling
>>>>> with GCC, the option -std=gnu99 is now added to the CFLAGS by
>>>>> configure, if the compiler accepts it.
>>>>> 
>>>>> Signed-off-by: Jarno Rajahalme <jrajahalme at nicira.com>
>>>> 
>>>> Are you sure that this line in configure.ac isn't the root of the
>>>> problem?
>>>> 
>>>> OVS_ENABLE_OPTION([-Wdeclaration-after-statement])
>>> 
>>> I did not notice this, sorry. It turned out to be the problem, so there is no need to add the -std option.
>>> 
>>> I left in the change in transliterating the ?=? as well as ?-? to ?_? so that if we ever need to add options with ?=? in them, there should be no problems in doing so.
>>> 
>>>> 
>>>> I'm still really nervous about this one (I think it often uglifies code)
>>>> but let's give it a shot:
>>>> 
>>> 
>>> If it turns out to be too ugly we can always take this one back.
>>> 
>>>>> -    * Don't mix declarations and code within a block.
>>>>> +    * Mixing of declarations and code within a block.
>>>> 
>>>>> +  Don't use other C99 features that are not widely implemented in
>>>>> +older compilers:
>>>>> +
>>>> 
>>>> We have enough of these in the source that I think they're not a problem
>>>> in practice anymore, so let's delete this one too:
>>>> 
>>>>>    * Don't put a trailing comma in an enum declaration (e.g. don't
>>>>>      write "enum { x = 1, };").
>>>> 
>>> 
>>> Ok, I?ll change this too. How about this incremental:
>> 
>> That's fine, thank you.
>> _______________________________________________
>> dev mailing list
>> dev at openvswitch.org
>> http://openvswitch.org/mailman/listinfo/dev




More information about the dev mailing list