www.digitalmars.com         C & C++   DMDScript  

D - Feature request: <struct>.offsetof(<member>) property

reply Dan Liebgold <Dan_member pathlink.com> writes:
What I would like to have is a <type>.offsetof(<datamember>) property for struct
or union types. In C/C++ the preprocessor is used for this purpose, for example
(from windows):

#define FIELD_OFFSET(type, field)    ((ulong)(ulong*)&(((type *)0)->field))

Is there currently a way to do this in D?

Dan
Feb 24 2003
next sibling parent "Achilleas Margaritis" <axilmar in.gr> writes:
Good idea. Maybe it can be done in an OO way as a static property:

<struct>.<member>.offset

"Dan Liebgold" <Dan_member pathlink.com> wrote in message
news:b3cluc$23e8$1 digitaldaemon.com...
 What I would like to have is a <type>.offsetof(<datamember>) property for

 or union types. In C/C++ the preprocessor is used for this purpose, for

 (from windows):

 #define FIELD_OFFSET(type, field)    ((ulong)(ulong*)&(((type

 Is there currently a way to do this in D?

 Dan

Feb 24 2003
prev sibling parent "Walter" <walter digitalmars.com> writes:
"Dan Liebgold" <Dan_member pathlink.com> wrote in message
news:b3cluc$23e8$1 digitaldaemon.com...
 What I would like to have is a <type>.offsetof(<datamember>) property for

 or union types. In C/C++ the preprocessor is used for this purpose, for

 (from windows):

 #define FIELD_OFFSET(type, field)    ((ulong)(ulong*)&(((type

 Is there currently a way to do this in D?

Yes; tag.member.offset should do it. -Walter
Feb 24 2003