Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[JW] can an expression be a member-designator in offsetof macro

0 views
Skip to first unread message

Jun Woong

unread,
Aug 12, 2001, 8:52:07 AM8/12/01
to
Hi,

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

Douglas A. Gwyn

unread,
Aug 14, 2001, 10:08:24 AM8/14/01
to
Jun Woong wrote:
> offsetof(type, member-designator)
> In use of offsetof macro, can an expression be member-designator?

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.

Jun Woong

unread,
Aug 14, 2001, 12:59:21 PM8/14/01
to
In article <3B7930D8...@null.net>, Douglas A. Gwyn says...

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?

Douglas A. Gwyn

unread,
Aug 14, 2001, 4:21:35 PM8/14/01
to
Jun Woong wrote:
> Do you mean that the member-designator can be only a *name* of a
> member?

I mean, bar_o.b[3] is not a member of struct foo.
struct foo has one member, designated by bar_o.

0 new messages