Is there a way in gcc where I could define a structure with a specific member at a specific offset?
I want to define the structure as follows:
struct { .offset(0xDC)
and then the following statement:
int a = foo.bar
will be identical to the statement:
int a = *(int*)((char*)&foo + 0xDC);
* UPDATE *
Some prerequisites: I want to access the elements in the exported structure that does not have the correct definition, it has many members, and I take care of only a few of them, and their offset (determination of the initial structure) is slightly different on each target platform (I need compile my code for several different platforms)
I considered the add-on option mentioned in the comments here, but it requires me to do some annoying calculations every time I want to add a member. eg:
strcut { .offset(0xDC) int bar; .offset(0xF4) int moo; }foo;
simpler:
struct __attribute__ ((__packed__)) struct { char pad1[0xD8]; int bar; char pad2[0x18]; int moo; }foo;
and that, without taking into account the fact that sizeof (int) can change from platform to platform
c ++ c gcc
t_z
source share