
Respected Sir,
How can I determine the byte offset of a field within a structure?
How can I access structure fields by name at run time?
please help me sir .
Thank you sir !!!

hi, Srinivasan
(i)In c offsetof() macro is defined in <stddef.h>. With the help of it you can compute the offset field in structure struct s as offsetof(type,field).
#include <stddef.h>
size_t offsetof(type, field);
e.g.
struct st { int a, b; };
offsetof(struct st, b);
(char *) casting arranges that the offset so computed is a byte offset.
(ii)Maintain the offsets field computed by the offsetof() macro.
*(int *)((char *)stp + offsetf) = value;
in the above the value of f can be set indirectly, here stp is the pointer to an instance of the srurcture and the field is an int which has the offset offsetf.
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.