On Tue, Mar 24, 2009 at 8:32 AM, Joseph S. Myers <jos...@codesourcery.com> wrote: > 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 6.7.2.1 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.
Well, gcc has to follow an ABI to pass the [0] case. > 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. > On x86-64, gcc 4.3 passes/returns struct line { int length; char contents[]; }; in memory and passes/returns struct line { int length; char contents[0]; }; in register. I couldn't find anything in psABI which mandates such behaviors. -- H.J.