KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm looking for a piece of code that can tell me the offset of a field within a structure without allocating an instance of the structure. IE: given struct mstct { int myfield; int myfield2; }; I could write: mstct thing; printf("offset %lu\n", (unsigned long)(&thing.myfield2 - &thing)); And get offset 4 for the output. How can I do it without that mstct thing declaration/allocating one? I know that &<struct> does not always point at the first byte of the first field of the structure, I can account for that later.
Tags (comma-separated)
Save Edits
Cancel