If you want to do pointer math like this you need to convert to a char pointer. The reason for this is illustrated below:
1 2 3 4 5
|
int* foo = new int[10];
int* a = &foo[1];
int* b = foo + 1;
// note: a == b
|
Therefore if you do this:
1 2 3
|
SOMESTRUCT s;
ptr = &s + sizeof(int);
|
You're actually pulling from a different (nonexistant) struct. Same as if you were doing this:
Therefore if you want to get members within the struct, you could (BUT SHOULDN'T) do this:
1 2 3 4 5 6
|
STRUCTURE s;
char* p = reinterpret_cast<char*>(&s); // make it a char pointer
// this way pointer math increments by bytes instead of by sizeof(struct)s
float afloat;
memcpy( &afloat, p + sizeof(int), sizeof(afloat) );
|
Of course.... this comes with the expected disclaimers:
1) This is atrociously messy
2) As you can see, it's dangerous unless you're very careful
3) It isn't even guaranteed to work because the compiler can rearrange that struct however it wants, add padding, etc in order to make accessing members more efficient.
4) There's no point to doing this because you can just access members the "normal way".
EDIT: man I was way too slow =(