Subject: Re: Question regarding the array of size 0.
To: Alfred Perlstein <bright@wintelcom.net>
From: Harti Brandt <brandt@fokus.gmd.de>
List: tech-kern
Date: 03/30/2001 10:04:45
On Thu, 29 Mar 2001, Alfred Perlstein wrote:

AP>* Peter Seebach <seebs@plethora.net> [010329 23:49] wrote:
AP>> In message <200103300647.WAA25263@shell17.ba.best.com>, Todd Whitesel writes:
AP>> >Just put a 1-element array at the end of your header struct, and account for
AP>> >it when you work out how much extra space to allocate. C memory layout rules
AP>> >guarantee that this usage will have the desired effect.
AP>>
AP>> Nope, not portable.  The implementation is allowed to bust you for
AP>> overstepping the bounds of the array.  :)
AP>>
AP>> The only portable solution is the new feature in C99.
AP>
AP>Which new feature?

struct foo {
	double	bar;
	int	baz[];
};

I suppose. But neither gcc nor Sun-cc seem to support it :-(

# gcc -c x.c
x.c:3: field `baz' has incomplete type

# cc -c x.c
"x.c", line 3: null dimension: baz
cc: acomp failed for x.c

Well, that's even lesser portability.

struct foo {
	double	bar;
	int	baz[0];
};

works for both compilers.
-- 
harti brandt, http://www.fokus.gmd.de/research/cc/cats/employees/hartmut.brandt/private
              brandt@fokus.gmd.de, harti@begemot.org