KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Is there a way in gcc, where I could define a struct with a specific member in a specific offset? I want to define a struct in the following way: struct { .offset(0xDC) //or something equivalent int bar; } foo; and then the following statement: int a = foo.bar will be identical to the statement: int a = *(int*)((char*)&foo + 0xDC); * UPDATE * Some background: I want to access members in an exported struct which I have no proper definition, it has many members - which I care about only a handful of them, and their offset (the struct original definition) is a bit different on each target platform (I need to compile my code for a few different platforms) I have considered the padding option mentioned on the comments here, but it requires me to do some annoying calculations each time I want to add a member. for example: strcut { .offset(0xDC) int bar; .offset(0xF4) int moo; }foo; is simpler then: struct __attribute__ ((__packed__)) struct { char pad1[0xD8]; int bar; char pad2[0x18]; int moo; }foo; and that without taking into consideration the fact the sizeof(int) can change from platform to platform
Tags (comma-separated)
Save Edits
Cancel