Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 30 Mar 2001 10:04:45 +0200 (CEST)
From:      Harti Brandt <brandt@fokus.gmd.de>
To:        Alfred Perlstein <bright@wintelcom.net>
Cc:        Peter Seebach <seebs@plethora.net>, Todd Whitesel <toddpw@best.com>, <tech-kern@netbsd.org>, <freebsd-hackers@FreeBSD.ORG>
Subject:   Re: Question regarding the array of size 0.
Message-ID:  <Pine.BSF.4.33.0103301000020.476-100000@beagle.fokus.gmd.de>
In-Reply-To: <20010329235022.W9431@fw.wintelcom.net>

next in thread | previous in thread | raw e-mail | index | archive | help
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


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.33.0103301000020.476-100000>