prev up next   top/contents search

comp.lang.c FAQ list · Question 2.15

Q: How can I access structure fields by name at run time?


A: Keep track of the field offsets as computed using the offsetof() macro (see question 2.14). If structp is a pointer to an instance of the structure, and field f is an int having offset offsetf, f's value can be set indirectly with

	*(int *)((char *)structp + offsetf) = value;


prev up next   contents search
about this FAQ list   about eskimo   search   feedback   copyright

Hosted by Eskimo North