[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20200207163740.GA720553@xz-x1>
Date: Fri, 7 Feb 2020 11:37:40 -0500
From: Peter Xu <peterx@...hat.com>
To: Sean Christopherson <sean.j.christopherson@...el.com>
Cc: Paolo Bonzini <pbonzini@...hat.com>,
Paul Mackerras <paulus@...abs.org>,
Christian Borntraeger <borntraeger@...ibm.com>,
Janosch Frank <frankja@...ux.ibm.com>,
David Hildenbrand <david@...hat.com>,
Cornelia Huck <cohuck@...hat.com>,
Vitaly Kuznetsov <vkuznets@...hat.com>,
Wanpeng Li <wanpengli@...cent.com>,
Jim Mattson <jmattson@...gle.com>,
Joerg Roedel <joro@...tes.org>, Marc Zyngier <maz@...nel.org>,
James Morse <james.morse@....com>,
Julien Thierry <julien.thierry.kdev@...il.com>,
Suzuki K Poulose <suzuki.poulose@....com>,
linux-mips@...r.kernel.org, kvm@...r.kernel.org,
kvm-ppc@...r.kernel.org, linux-arm-kernel@...ts.infradead.org,
kvmarm@...ts.cs.columbia.edu, linux-kernel@...r.kernel.org,
Christoffer Dall <christoffer.dall@....com>,
Philippe Mathieu-Daudé <f4bug@...at.org>
Subject: Re: [PATCH v5 18/19] KVM: Dynamically size memslot array based on
number of used slots
On Fri, Feb 07, 2020 at 08:15:53AM -0800, Sean Christopherson wrote:
> On Fri, Feb 07, 2020 at 11:05:46AM -0500, Peter Xu wrote:
> > On Fri, Feb 07, 2020 at 07:38:29AM -0800, Sean Christopherson wrote:
> > > On Thu, Feb 06, 2020 at 05:12:08PM -0500, Peter Xu wrote:
> > > > This patch is tested so I believe this works, however normally I need
> > > > to do similar thing with [0] otherwise gcc might complaint. Is there
> > > > any trick behind to make this work? Or is that because of different
> > > > gcc versions?
> > >
> > > array[] and array[0] have the same net affect, but array[] is given special
> > > treatment by gcc to provide extra sanity checks, e.g. requires the field to
> > > be the end of the struct. Last I checked, gcc also doesn't allow array[]
> > > in unions. There are probably other restrictions.
> > >
> > > But, it's precisely because of those restrictions that using array[] is
> > > preferred, as it provides extra protections, e.g. if someone moved memslots
> > > to the top of the struct it would fail to compile.
> >
> > However...
> >
> > xz-x1:tmp $ cat a.c
> > struct a {
> > int s[];
> > };
> >
> > int main(void) { }
> > xz-x1:tmp $ make a
> > cc a.c -o a
> > a.c:2:9: error: flexible array member in a struct with no named members
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
> gcc is telling you quite explicitly why it's angry. Copy+paste from the
> internet[*]:
>
> Flexible Array Member(FAM) is a feature introduced in the C99 standard of the
> C programming language.
>
> For the structures in C programming language from C99 standard onwards, we
> can declare an array without a dimension and whose size is flexible in nature.
>
> Such an array inside the structure should preferably be declared as the last
> member of structure and its size is variable(can be changed be at runtime).
>
> The structure must contain at least one more named member in addition to the
> flexible array member.
>
> [*] https://www.geeksforgeeks.org/flexible-array-members-structure-c/
Sorry again for not being able to identify the meaning of that
sentence myself. My English is probably even worse than I thought...
So I think my r-b keeps.
Thanks,
--
Peter Xu
Powered by blists - more mailing lists