In article <hb**************@bombur.uio.no>,
Hallvard B Furuseth <h.**********@usit.uio.nowrote:
>to find the required alignment of a struct, I've used
#include <stddef.h>
struct Align_helper {
char dummy;
struct S align;
};
enum { S_alignment = offsetof(struct Align_helper, align) };
gcc -std=c99 -pedantic says that is invalid if S has a flexible array
member:
struct S {
int a;
char c[];
};
Is there some way to find the alignment of that struct?
Interesting. This might be more of a comp.std.c question: I assume
gcc is unhappy because a flexible array member (FAM) must, for
obvious reasons, be the last member of a "struct". Here the FAM
is the last element of an embedded sub-struct, and the sub-struct
is the last member of the top-level struct. So the FAM *is* in fact
the last member, but this can only be determined by "deep" inspection
instead of "shallow" inspection. (We can continue embedding a
struct within a struct within a struct to produce any desired
inspection depth:
struct S100 { struct S99 { struct S98 { ... struct S01 {
struct S00 { size_t fam_size; char fam[]; } lastelem;
} lastelem; } lastelem; ... } lastelem };
The inspection depth required here is 101.)
Does C99 really require that FAMs be discoverable by what I have
called "shallow" inspection? If not, it seems to me that gcc is
wrong here, and your trick should work; if so, gcc is right.
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it
http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.