qemu-trivial
[Top][All Lists]
Advanced

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

Re: [Qemu-trivial] [Qemu-devel] [PATCH for-2.10] util/oslib-posix.c: Avo


From: Eric Blake
Subject: Re: [Qemu-trivial] [Qemu-devel] [PATCH for-2.10] util/oslib-posix.c: Avoid warning on NetBSD
Date: Fri, 21 Jul 2017 07:54:03 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1

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 <address@hidden> 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: signature.asc
Description: OpenPGP digital signature


reply via email to

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