This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Should structure with flexible array be allowed to be passed by value?

On Tue, 24 Mar 2009, H.J. Lu wrote:

> > I see nothing about passing by value different from structure assignment,
> > which ignores the flexible array member (see paragraph 22 (in
> > N1256) for an example stating this). ?Although argument passing and return
> > aren't strictly assignments, they generally act in the same way, so such a
> > structure passed by value or used as a function return value loses the
> > flexible array members in the process. ?I suppose an optional warning for
> > this might be useful.
> >
> How should be they passed on x86-64? psABI isn't clear and gcc isn't consistent
> with char contents[0] vs char contents[].

The [0] case is outside the scope of ISO C and so outside the scope of any 
ABI that limits itself to ISO C.

For the [] case, it's a good question that could affect not just the 
x86-64 ABI but various other processor ABIs that look at the elements of 
structures (not just their sizes) to determine how they are passed - it 
would be useful to add target-independent tests to the compat testsuite so 
compatibility of GCC with itself and GCC with other compilers can be 
tested in this regard.  They'd cover various combinations of types for the 
first element or first few elements, and the final [] array - both for 
argument passing and for function return.

Joseph S. Myers

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]