This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: flexible array member size
- To: Richard Henderson <rth at twiddle dot net>
- Subject: Re: flexible array member size
- From: "Joseph S. Myers" <jsm28 at cam dot ac dot uk>
- Date: Sat, 2 Dec 2000 00:38:04 +0000 (GMT)
- cc: <gcc-bugs at gcc dot gnu dot org>
On Fri, 1 Dec 2000, Richard Henderson wrote:
> struct s {
> int x;
> int y[];
> } s;
>
> char test[sizeof (s.y) == 0 ? 1 : -1];
Treating the type as incomplete seems the most plausible and consistent
with 6.7.2.1p16 to me. It certainly can't have size zero; the C standard
has no notion of objects of size zero. It hardly makes sense to attempt
to apply the requirements that
Second, when a . (or ->) operator
has a left operand that is (a pointer to) a structure with a
flexible array member and the right operand names that
member, it behaves as if that member were replaced with the
longest array (with the same element type) that would not
make the structure larger than the object being accessed;
the offset of the array shall remain that of the flexible
array member, even if this would differ from that of the
replacement array. If this array would have no elements, it
behaves as if it had one element but the behavior is
undefined if any attempt is made to access that element or
to generate a pointer one past it.
in the context of sizeof, but try comp.std.c if it seems that this wording
just confuses the issue of what to do with sizeof in such a case.
--
Joseph S. Myers
jsm28@cam.ac.uk