On a project I need to get the offset of particular structure members. However I can't use any macros. So I tried to take the logic behind this
#define OFFSETOF(struct_name, fld_name) \
(unsigned int)&(((struct_name *)0)->fld_name)
And to transform it into a function which gives me this.
unsigned long offset_of_1(void *ptr, void *field)
{
return ((unsigned long)field - (unsigned long)ptr);
}
It works as long as I use a structure that has been initialized, it is the only work around I found that seems to be working. But I was wondering if there was a better way of doing this ?