This is the mail archive of the 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]

Re: invalid offsetof from non-POD type

John Quigley wrote:
Perhaps it would be useful if I described how the code that I'm working on uses offsetof. It is the Torque game engine from The engine has an internal c-like scripting language. The fields and methods of the c++ classes in the engine can be exposed to this scripting language. For each field, the engine uses offsetof to compute the offset of the field in the class. Later on, when the scripts read or write to the field, the script runtime locates the field by adding the offset to the base pointer of the object in question.
yeah, I understand the idiom. what you really want is a pointer to void data
member. One way to get what you want is something like
#define myoff(T,m) ((size_t)(&((T *)1)->m) - 1)
a) circumvents g++'s invalid offsetof check
b) allows m to be from a base, and DTRT if the base is not at offset zero
c) DTWT for virtual bases and reference members

BTW, do people do things like
	offsetof (T, m.sub_m)
? I don't think it blessed by the C/c++ std, but falls out of the common
implementation of offsetof.


Nathan Sidwell    ::   ::     CodeSourcery LLC
         The voices in my head said this was stupid too
nathan at codesourcery dot com : : nathan at acm dot org

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