Not sure if this is exactly what you are looking for, but here is a pretty close solution using offsetof:
struct Test
{
int x;
int y;
};
void example(void *base, size_t offset)
{
int *adr;
adr = (int*)((char*)base + offset);
printf("%d\n", *adr);
}
int main(int argc, char **argv)
{
struct Test t;
t.x = 5;
t.y = 10;
example(&t, offsetof(struct Test, y));
}
source
share