edit: that was a failure, just use gcc (dunno if you can with visual studio/cl) and offsetof
edit: If you're using cl and it doesn't have offsetof or vs doesn't
Code:
#define offsetof(type, field) ((int) (& (((type *) 0)->field)))
edit: edit: edit:
sorry, I dropped the code
Code:
int main(...)
{
...
struct structType *aStruct;
AccessArbitraryField(aStruct, offsetof(structType, fieldName);
...
}
AccessArbitraryField(void *aStruct, int fOff)
{
access it as *(aStruct + fOff)
}
I think that should work