This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

C99 conformance bug in gcc-3.1


The web pages about C99 conformance in gcc list "flexible array members"
as "done" (with one caveat about constraint checking) but there is a
bug in the implementation. Section 6.7.2.1 paragraph 15 says "the size
of the structure shall be equal to the offset of the last element of an
otherwise identical structure that replaces the flexible array member
with an array of unspecified length", however gcc may add padding after
the flexible array member. The numbers produced by the following program
should all be equal.

$ cat test.c 
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>

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

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

int
main(void)
{
        printf("sizeof(struct foo) = %u\n", sizeof(struct foo));
        printf("offsetof(struct foo, pad) = %u\n", offsetof(struct foo, pad));
        printf("offsetof(struct bar, pad) = %u\n", offsetof(struct bar, pad));
        return(0);
}
$ gcc test.c
$ ./a.out 
sizeof(struct foo) = 8
offsetof(struct foo, pad) = 6
offsetof(struct bar, pad) = 6
$

Tony.
-- 
f.a.n.finch <dot@dotat.at> http://dotat.at/
BAILEY: CYCLONIC 3 IN NORTH AT FIRST, OTHERWISE WESTERLY 4 OR 5, OCCASIONALLY
6. RAIN OR SQUALLY SHOWERS. MODERATE OR GOOD.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]