bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] avoid warnings about initialization of automatic aggregates


From: Pádraig Brady
Subject: Re: [PATCH] avoid warnings about initialization of automatic aggregates
Date: Tue, 2 Dec 2008 09:36:28 +0000
User-agent: Thunderbird 2.0.0.6 (X11/20071008)

Jim Meyering wrote:
> Pádraig Brady <address@hidden> wrote:
>> Jim Meyering wrote:
>>> Finally getting serious about avoiding warnings,
>>> I've just eliminated this batch:
>>>
>>> >From c58b5daa337b16416be50adfeb3e99e3c009c891 Mon Sep 17 00:00:00 2001
>>> From: Jim Meyering <address@hidden>
>>> Date: Sun, 30 Nov 2008 22:37:42 +0100
>>> Subject: [PATCH] avoid warnings about initialization of automatic aggregates
>>>
>>> * src/system.h (DZA_CONCAT0, DZA_CONCAT): New macros.
>>> (DECLARE_ZEROED_AGGREGATE): New macro.
>> Some notes on this issue:
>> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36750
>> So the warning can be suppressed in gcc with
>> -Wno-missing-field-initializers
> 
> Thanks.  However, I prefer not to use this -Wno... option, because
> it could later hide some legitimate warnings in the affected files.

Absolutely.

Thinking a bit more about your patch, I'm not sure about the use of
static variables as this is a logically different thing. I.E. the static
variables will only be initialised at program start, whereas 'type var =
{0,}' would be initialised each time the scope is entered.
For e.g. I think quote_name() in ls.c will now behave differently?

I think you did this to support using this at global scope, but that
also has the caveat that static is overloaded to mean don't export in
that case. Or perhaps you meant to only do compile tests with
-Wmissing-field-initializers (and -Dlint), but I think it would be nice
to be able to test binaries built in this mode.

Would it be better just to use memset() and restrict usage to automatic
variables? For global scope one can use static if appropriate If we
restrict it to auto variables and considering you can use {0, } to init
scalar variables also, I would rename the macro to:

/* With -Dlint, avoid overzealous gcc -Wmissing-field-initializers warning
   about code like mbstate_t m = {0,}; */
#ifdef lint
# define DECLARE_ZEROED_AUTO(Type, Var) \
   Type Var; memset(&Var, 0, sizeof Var)
#else
# define DECLARE_ZEROED_AUTO(Type, Var) \
  Type Var = { 0, }
#endif


>> I must dust off and split up my patch
>> to allow us to use -Wsign-compare
> 
> Please tread lightly there.  Or maybe even not at all ;-)
> Given our penchant for avoiding casts, that might not be soluble.

Sure, I think my previous patch set had only net 3 new casts.
I'll see if I can do better, as -Wsign-compare really does
find bugs in my code at least.

cheers,
Pádraig.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]