Newsgroups: comp.lang.c Path: utzoo!henry From: henry@utzoo.uucp (Henry Spencer) Subject: Re: struct accessing Message-ID: <1989Jun23.170331.23166@utzoo.uucp> Organization: U of Toronto Zoology References: <1545@stl.stc.co.uk> Date: Fri, 23 Jun 89 17:03:31 GMT In article <1545@stl.stc.co.uk> dsr@stl.stc.co.uk (David Riches) writes: >Now, I have a variable which tells me the name of the field in fred >which I would like to look at, e.g. field_name... >What I'm doing at the moment is using a case statement to interrogate >field_name... >This gets messy when the struct gets big. Is there a more subtle way >of doing this? For instance, in my dreams, I would like to have a >statement which says :- > > person = fred.$field_name$ There is no non-messy way of doing this in C. Somewhere there has to be a table mapping names into members; C does not normally keep such a thing around at run time, so you have to supply it yourself. -- NASA is to spaceflight as the | Henry Spencer at U of Toronto Zoology US government is to freedom. | uunet!attcan!utzoo!henry henry@zoo.toronto.edu