I have tried to wrap my head around this for some time now, and have searched for related questions. I have found some answers that make some sense, but apparently I need this carved in stone.
Currently I'm in the process of learning some firmware for a product. A set of pointers have been initialized as uint8_t
, like the following example:
uint8_t *pwhatevs;
The sizeof
the above would return 1
(one byte). When this pointer is assigned later in the firmware, it is pointing to a 32-bit address in the following way:
pwhatevs = (uint8_t *)&whatever;
This syntax appears odd to me. The initial part (uint8_t *)
is an 8-bit pointer typecast. But if I take the sizeof pwhatevs
now it returns 4
(4 bytes), which I'm both not surprised of but then again very surprised due to the pointer typecast. Can someone explain this? If additional information is needed I will provide as much as I can!
Edit: In another question relating to pointer size it was mentioned that the size of a pointer is system dependent like 16, 32 or 64 bits. This does make sense, but then why is the *pwhatevs
when initialized not 4 bytes in size?
Edit 2: I can't share the entire code since it is an actual product, but will do it the following way. If this isn't sufficient, I will have to work on a specific example.