Manipulating the address of a variable to store a smaller type?
Posted
by Sidnicious
on Stack Overflow
See other posts from Stack Overflow
or by Sidnicious
Published on 2010-06-07T20:52:39Z
Indexed on
2010/06/07
21:02 UTC
Read the original article
Hit count: 283
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;
© Stack Overflow or respective owner