From: Al Viro <viro@zeniv.linux.org.uk>
To: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Cc: Dan Carpenter <dan.carpenter@oracle.com>,
Russell King - ARM Linux admin <linux@armlinux.org.uk>,
Leon Romanovsky <leon@kernel.org>, Joe Perches <joe@perches.com>,
Dwaipayan Ray <dwaipayanray1@gmail.com>,
Andy Whitcroft <apw@canonical.com>,
Lukas Bulwahn <lukas.bulwahn@gmail.com>,
linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org,
Julia Lawall <julia.lawall@inria.fr>
Subject: Re: [PATCH] checkpatch: prefer = {} initializations to = {0}
Date: Sat, 14 Aug 2021 14:52:31 +0000 [thread overview]
Message-ID: <YRfYr0fsM1R7O5x6@zeniv-ca.linux.org.uk> (raw)
In-Reply-To: <1b94e688-a070-998a-3014-96bcbaed4cae@wanadoo.fr>
On Sat, Aug 14, 2021 at 03:59:22PM +0200, Christophe JAILLET wrote:
> > +# prefer = {}; to = {0};
> > + if ($line =~ /= \{ *0 *\}/) {
> > + WARN("ZERO_INITIALIZER",
> > + "= {} is preferred over = {0}\n" . $herecurr);
Sigh... "is preferred over" by whom? Use the active voice, would you?
> [1] and [2] state that {} and {0} don't have the same effect. So if correct,
> this is not only a matter of style.
>
> When testing with gcc 10.3.0, I arrived at the conclusion that both {} and
> {0} HAVE the same behavior (i.e the whole structure and included structures
> are completely zeroed) and I don't have a C standard to check what the rules
> are.
> gcc online doc didn't help me either.
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf, but empty
initializer-list is gccism anyway.
Section 6.7.8 is the one to look through there.
> Can someone provide some rational or compiler output that confirms that {}
> and {0} are not the same?
Easily: compare
int x[] = {0};
and
int x[] = {};
For more obscure example,
int x = {0};
is valid, if pointless, but
int x = {};
will be rejected even by gcc.
Incidentally, do *NOT* assume that initializer will do anything with padding
in a structure, no matter how you spell it. Neither {} nor {0} nor explicit
initializer for each member of struct do anything to the padding. memset()
does, but anything short of that leaves the padding contents unspecified.
next prev parent reply other threads:[~2021-08-14 14:57 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-05 10:43 [PATCH] checkpatch: prefer = {} initializations to = {0} Dan Carpenter
2021-08-05 12:27 ` Joe Perches
2021-08-05 18:04 ` Joe Perches
2021-08-05 18:17 ` Julia Lawall
2021-08-05 18:28 ` Joe Perches
2021-08-05 18:44 ` Julia Lawall
2021-08-14 13:59 ` Christophe JAILLET
2021-08-14 13:59 ` Christophe JAILLET
2021-08-14 14:05 ` Marion & Christophe JAILLET
2021-08-14 14:38 ` Leon Romanovsky
2021-08-14 14:57 ` Al Viro
2021-08-14 15:52 ` Leon Romanovsky
2021-08-14 16:45 ` Al Viro
2021-08-14 14:44 ` Russell King (Oracle)
2021-08-14 14:52 ` Al Viro [this message]
2021-08-14 20:20 ` Christophe JAILLET
2021-08-16 6:55 ` Dan Carpenter
2021-08-16 7:23 ` Russell King (Oracle)
2021-08-16 19:05 ` Dan Carpenter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YRfYr0fsM1R7O5x6@zeniv-ca.linux.org.uk \
--to=viro@zeniv.linux.org.uk \
--cc=apw@canonical.com \
--cc=christophe.jaillet@wanadoo.fr \
--cc=dan.carpenter@oracle.com \
--cc=dwaipayanray1@gmail.com \
--cc=joe@perches.com \
--cc=julia.lawall@inria.fr \
--cc=kernel-janitors@vger.kernel.org \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=lukas.bulwahn@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox