From: Eric Blake <eblake@redhat.com>
To: Kamil Rytarowski <n54@gmx.com>, Peter Maydell <peter.maydell@linaro.org>
Cc: QEMU Developers <qemu-devel@nongnu.org>,
QEMU Trivial <qemu-trivial@nongnu.org>,
Kamil Rytarowski <kamil@netbsd.org>,
"patches@linaro.org" <patches@linaro.org>
Subject: Re: [Qemu-devel] [Qemu-trivial] [PATCH for-2.10] util/oslib-posix.c: Avoid warning on NetBSD
Date: Fri, 21 Jul 2017 07:54:03 -0500 [thread overview]
Message-ID: <0b389a73-243c-71fa-8a3f-f8af79f487b0@redhat.com> (raw)
In-Reply-To: <9b0800b8-b13f-67b3-a21f-96a6ba8d0a99@gmx.com>
[-- Attachment #1: Type: text/plain, Size: 2251 bytes --]
On 07/21/2017 07:18 AM, Kamil Rytarowski wrote:
> On 21.07.2017 12:22, Peter Maydell wrote:
>> On 20 July 2017 at 19:26, Eric Blake <eblake@redhat.com> wrote:
>>> On 07/20/2017 11:32 AM, Peter Maydell wrote:
>>>> On NetBSD the compiler warns:
>>>> util/oslib-posix.c: In function 'sigaction_invoke':
>>>> util/oslib-posix.c:589:5: warning: missing braces around initializer [-Wmissing-braces]
>>>> siginfo_t si = { 0 };
>>>> ^
>>>
>>> Uggh. That is a broken compiler. C99 declares that 'anything = {0}' is
>>> supposed to be a valid way to zero-initialize anything.
>>>
>
> Not necessarily broken compiler. According to strict C standard we need
> to initialize it in this case with "{{0}}"... which is ugly.
No, the C standard SPECIFICALLY allows for missing {}, so that {0} is
the universal zero-initializer.
typedef union siginfo {
char si_pad[128]; /* Total size; for future expansion */
struct _ksiginfo _info;
} siginfo_t;
C99 6.7.8 Initialization paragraph 20
> If the aggregate or union contains elements or members that are aggregates or unions,
> these rules apply recursively to the subaggregates or contained unions. If the initializer of
> a subaggregate or contained union begins with a left brace, the initializers enclosed by
> that brace and its matching right brace initialize the elements or members of the
> subaggregate or the contained union. Otherwise, only enough initializers from the list are
> taken to account for the elements or members of the subaggregate or the first member of
> the contained union; any remaining initializers are left to initialize the next element or
> member of the aggregate of which the current subaggregate or contained union is a part.
and also gives an example of missing braces being valid, in paragraph 28:
> EXAMPLE 5
> The declaration
> struct { int a[3], b; } w[] = { { 1 }, 2 };
> is a definition with an inconsistently bracketed initialization. It defines an array with two element
> structures: w[0].a[0] is 1 and w[1].a[0] is 2; all the other elements are zero.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 619 bytes --]
prev parent reply other threads:[~2017-07-21 12:54 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-20 16:32 [Qemu-devel] [PATCH for-2.10] util/oslib-posix.c: Avoid warning on NetBSD Peter Maydell
2017-07-20 18:26 ` Eric Blake
2017-07-20 20:53 ` Peter Maydell
2017-07-20 21:10 ` Eric Blake
2017-07-20 21:20 ` Peter Maydell
2017-07-21 10:22 ` Peter Maydell
2017-07-21 12:18 ` [Qemu-devel] [Qemu-trivial] " Kamil Rytarowski
2017-07-21 12:54 ` Eric Blake [this message]
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=0b389a73-243c-71fa-8a3f-f8af79f487b0@redhat.com \
--to=eblake@redhat.com \
--cc=kamil@netbsd.org \
--cc=n54@gmx.com \
--cc=patches@linaro.org \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.org \
/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;
as well as URLs for NNTP newsgroup(s).