offsetof(type, member-designator)
In use of offsetof macro, can an expression be member-designator?
The Standard only requires &(t.member-designator) to be evaluated
to a constant address where t is declared as "static type t".
In other words, are the followings valid?
struct bar { char a, b[10]; };
struct foo {
struct bar bar_o;
};
offsetof(struct bar, b[3]);
offsetof(struct foo, bar_o.a);
offsetof(struct foo, bar_o.b[3]);
Thanks in advance...
--
Jun Woong (myco...@hanmail.net)
Dept. of Physics, Univ. of Seoul
Member designators are inherently not expressions.
> The Standard only requires &(t.member-designator) to be evaluated
> to a constant address where t is declared as "static type t".
Wrong. It also requires that a member of the structure
be designated by that member-designator.
Do you mean that the member-designator can be only a *name* of a
member?
That is,
struct bar { char a, b[10]; };
struct foo {
struct bar bar_o;
};
offsetof(struct bar, b[3]);
offsetof(struct foo, bar_o.a);
offsetof(struct foo, bar_o.b[3]);
the all three lines above have undefined behavior?
I don't see where I can get that conclusion. Does the "designator"
imply this?
I mean, bar_o.b[3] is not a member of struct foo.
struct foo has one member, designated by bar_o.