How to find the offset of a structure member just by knowing the structure name and the address of that member?????
void func(int *ptr)
//how to find the base address of structure.
//I know only the structure name i.e 'cook' and the address of b i.e 'ptr'
//If the offset to address b is found ,the base address can be found out!!!!!
offsetof cannot be used in this case because u dont know the member's name but only the address of that member :(
Whoever gave you this exercise is either mistaken that it's possible, or expecting a non-portable hack. Either way, you need to get clarification, because within standard C there's no solution. You simply cannot find the base address of a structure instance given only a pointer to one of its members and the structure name.