Manipulating the address of a variable to store a smaller type?
- by Sidnicious
This is what I get for pampering myself with high-level programming languages.
I have a function which writes a 32-bit value to a buffer, and a uint64_t on the stack. Is the following code a sane way to store it?
uint64_t size = 0;
// ...
getBytes((uint32_t*)&size+0x1);
I'm assuming that this would be the canonical, safe style:
uint64_t size = 0;
// ...
uint32_t smallSize;
getBytes(&smallSize);
size = smallSize;