finding offset of a member in C structures

Doug Gwyn gwyn at smoke.brl.mil
Fri May 24 06:06:21 AEST 1991


In article <22138 at paperboy.OSF.ORG> dbrooks at osf.org (David Brooks) writes:
-In article <16236 at smoke.brl.mil>, gwyn at smoke.brl.mil (Doug Gwyn) writes:
-|> But that's merely a design botch, because in order to ask for the offset
-|> of a structure member one HAS to have a particular structure type in mind;
-|> to make any use of the information one has to have a suitable pointer at
-|> hand.
-This is probably dragging the point out too far, but no.  The XtOffset
-macro is used to initialize a static array-of-struct.  There is no reason
-to have a variable of the struct type in scope.

But the programmer can easily MAKE one simply by casting the polymorphic
array member type to whatever is being assumed for each use of the offset
macro in the initializer.  The "handle" needed is present, albeit not in
the final form you want.



More information about the Comp.lang.c mailing list