On Sat, 20 Feb 2016, Dimitry Andric wrote:
On 19 Feb 2016, at 16:49, Alan Somers <asom...@freebsd.org> wrote:
On Fri, Feb 19, 2016 at 5:24 AM, Sergey Kandaurov <pluk...@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
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"