Posted: Fri Aug 18, 2023 12:06 pm Post subject: Pointers and offsets
I am learning the concept of pointers and offsets. But I can't figure out why, is the first offset +0x10 in both 32bit and 64bit architecture - see the attachment
Does the base pointer always have offset 0x10 or are there any data stored? If I am correct, 0x10 offset is 16 bytes. But the pointer itself needs only 8 bytes for 64bit architecture and 4 bytes for 32 architecture.[/url]
There's nothing special about 0x10. It's just how far the value is offset from the start of the structure it's located in. In that image, it's just an example. You could make up any number you want and it would be equally valid for pedagogical purposes.
Values are often grouped into structures. These structures can also have other related values stored in them as well.
For example:
Code:
struct Location {
float x;
float y;
float z;
};
In this C struct, the float `x` is the very first member of the structure. It's at the very beginning of the struct, so its offset from the beginning of the struct is 0. `y` is offset 4 bytes from the start (floats take up 4 bytes), and `z` is offset 8 bytes from the start.
Floats take up 4 bytes regardless of if you're compiling for a 32-bit or 64-bit target, so it doesn't matter in this case.
If a structure has any pointers in it (e.g. vtable), then offsets could be different since addresses are 8 bytes in 64-bit targets instead of 4 for 32-bit targets. _________________
I don't know where I'm going, but I'll figure it out when I get there.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum