Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 30 May 2002 10:38:03 +0100
From:      Tony Finch <dot@dotat.at>
To:        Marcel Moolenaar <marcel@FreeBSD.org>
Cc:        cvs-committers@FreeBSD.org, cvs-all@FreeBSD.org
Subject:   Re: cvs commit: src/sys/sys gpt.h
Message-ID:  <20020530103803.D10098@chiark.greenend.org.uk>
In-Reply-To: <20020530094039.B10098@chiark.greenend.org.uk>; from dot@dotat.at on Thu, May 30, 2002 at 09:40:39AM %2B0100
References:  <200205300544.g4U5iN586002@freefall.freebsd.org> <20020530094039.B10098@chiark.greenend.org.uk>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, May 30, 2002 at 09:40:39AM +0100, Tony Finch wrote:
> On Wed, May 29, 2002 at 10:44:23PM -0700, Marcel Moolenaar wrote:
> > 
> >   o  Remove GCC specific attribute packed.
> >   o  Add incomplete array padding.
> 
> Note that the padding array you have added doesn't cover the padding in
> the struct that you are having trouble with: offsetof(struct gpt_hdr,
> padding) == sizeof(struct gpt_hdr), i.e. there are 4 bytes of padding
> before the incomplete array member. It's also a gratuitous C99ism --
> a comment would be better.

Actually, since you wouldn't have committed this without it getting the
results you expected, I've done some more research and it looks like
this is a C99 feature that gcc mis-implements, so you are depending on
a gcc bug.

fanf@ref5.freebsd.org:/d/home/fanf
: 0 ; cat test.c
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>

struct foo {
        int32_t a;
        int16_t b;
        char pad[];
} foo;

int
main(void)
{
        printf("sizeof(struct foo) = %u\n", sizeof(struct foo));
        printf("offsetof(struct foo, pad) = %u\n", offsetof(struct foo, pad));
        return(0);
}
fanf@ref5.freebsd.org:/d/home/fanf
: 0 ; gcc $FANFCFLAGS test.c
test.c:8: warning: ISO C89 does not support flexible array members
fanf@ref5.freebsd.org:/d/home/fanf
: 0 ; ./a.out 
sizeof(struct foo) = 8
offsetof(struct foo, pad) = 6
fanf@ref5.freebsd.org:/d/home/fanf
: 0 ; 

(gcc's implementation of inline is wrong, too)

Tony.
-- 
f.a.n.finch <dot@dotat.at> http://dotat.at/
WIGHT PORTLAND PLYMOUTH: SOUTHWEST VEERING WEST 3 OR 4, OCCASIONALLY 5 AT
FIRST. MAINLY FAIR. GOOD.

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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020530103803.D10098>