Date: Sat, 20 Feb 2016 13:18:53 +1100 (EST) From: Bruce Evans <brde@optusnet.com.au> To: Dimitry Andric <dim@freebsd.org> Cc: Alan Somers <asomers@freebsd.org>, Sergey Kandaurov <pluknet@gmail.com>, "src-committers@freebsd.org" <src-committers@freebsd.org>, "svn-src-all@freebsd.org" <svn-src-all@freebsd.org>, "svn-src-head@freebsd.org" <svn-src-head@freebsd.org> Subject: Re: svn commit: r295768 - head/usr.sbin/iostat Message-ID: <20160220130138.M1403@besplex.bde.org> In-Reply-To: <83BB8467-4C40-4CF1-B394-1376C9D97FCF@FreeBSD.org> References: <201602182008.u1IK81vg092127@repo.freebsd.org> <CAE-mSO%2B7p=Equq81PPQjfZv1piPydBr4Mnk363CEs3w9EXRi9w@mail.gmail.com> <CAOtMX2hyZ=GFgp8F6t0dMDYF5FSPdoP9KdMU7V5rmscpaPUnsw@mail.gmail.com> <83BB8467-4C40-4CF1-B394-1376C9D97FCF@FreeBSD.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On Sat, 20 Feb 2016, Dimitry Andric wrote: > On 19 Feb 2016, at 16:49, Alan Somers <asomers@freebsd.org> wrote: >> >> On Fri, Feb 19, 2016 at 5:24 AM, Sergey Kandaurov <pluknet@gmail.com> wrote: > ... >>>> -struct nlist namelist[] = { >>>> +static struct nlist namelist[] = { >>>> #define X_TTY_NIN 0 >>>> - { "_tty_nin" }, >>>> + { .n_name = "_tty_nin", >>>> + .n_type = 0, .n_other = 0, .n_desc = 0, .n_value = 0 }, >>>> [...] >>> >>> You unlikely need this excessive explicit zeroization. >>> In this case it is implicitly prezeroed. > ... >> Yeah, it was being implicitly zeroized before. But Clang complained >> about the structures being only partially initialized. Since the >> whole point of my commit was to increase the WARNS level, I explicitly >> zeroed the zero fields to silence Clang. > > You got this warning, most likely: > > usr.sbin/iostat/iostat.c:122:15: error: missing field 'n_type' initializer [-Werror,-Wmissing-field-initializers] > { "_tty_nin" }, > ^ > > This warning is only produced when you use -Wall -W, and then initialize > structs partially, i.e. you initialize some fields but not others. I > think this is a quite reasonable warning for a high warning level. No, this more than defeats the reason for existence of C99 initializers. With C90 initializors, you sometimes had to write initializers for all the fields between the 2 that you care about, and get the order and number of al the fields right. At least you didn't have to write initializers for the trailing fields. With compiler warnings about missing initializers, you also have to write initializers for trailing fields. I forget if C99 initializers allows mixing named fields with unnamed fields, but style rules shouldn't allow it. > On the other hand, if this kind of construct is used throughout the > tree, and it is not seen as a big problem, we can simply silence this > particular warning using -Wno-missing-field -initializers. There is > already quite a list of warnings which are suppressed by default, even > at WARNS=6, namely: > > -Wno-empty-body > -Wno-format-y2k > -Wno-pointer-sign > -Wno-string-plus-int > -Wno-unused-const-variable > -Wno-unused-parameter We started using it for lists of functions for vfs, where some of the entries should be optional but all had to be supplied, in the correct order, for C90 initializers. These lists were reduced from excessively dynamic lists, and they ended up with not many optional entries, so they don't use the feature of omitting optional entries much. Bruce Bruce
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20160220130138.M1403>