Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!shadooby!accuvax.nwu.edu!nucsrl!gore!jacob From: jacob@gore.com (Jacob Gore) Newsgroups: comp.lang.c Subject: Re: struct accessing Message-ID: <470001@gore.com> Date: 25 Jun 89 16:43:28 GMT References: <1545@stl.stc.co.uk> Reply-To: jacob@gore.com (Jacob Gore) Organization: Gore Enterprises Lines: 40 / comp.lang.c / dsr@stl.stc.co.uk (David Riches) / Jun 22, 1989 / struct fred { int tom; int dick; int harry; } ... in my dreams, I would like to have a statement which says :- person = fred.$field_name$ where $field_name$ means "take my contents and use that as the field name.". ---------- Something that comes close: struct fred { int tom; int dick; int harry; } fred_proto; #define TOM (&fred_proto.tom - &fred_proto) #define DICK (&fred_proto.dick - &fred_proto) #define HARRY (&fred_proto.harry - &fred_proto) ... int field_name; struct fred fred; int *person; ... person = &fred + field_name; Or some variation of the above, like #define FIELD(aStruct,offset) (*(&aStruct + offset)) int person = FIELD(fred,TOM); -- Jacob Gore Jacob@Gore.Com {oddjob,chinet,att}!nucsrl!gore!jacob