finding offset of a member in C structures
David Brooks
dbrooks at osf.org
Fri May 24 00:34:54 AEST 1991
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. The table information is
used by a generic procedure compiled separately, to fill in information
from an outside database using code that is probably itself non-portable-
but-invariably-works.
In practice, there are local variables of the same type later in the source
file, but they don't *have* to be there. They too could be separately
compiled.
As I said, I agree it's a design botch, and it's nice to have ANSI define
offsetof, but it is all done with good intentions, in the interests of
information hiding.
--
David Brooks dbrooks at osf.org
Systems Engineering, OSF uunet!osf.org!dbrooks
More information about the Comp.lang.c
mailing list