struct accessing

Henry Spencer henry at utzoo.uucp
Sat Jun 24 03:03:31 AEST 1989


In article <1545 at stl.stc.co.uk> dsr at 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 at zoo.toronto.edu



More information about the Comp.lang.c mailing list