Sunday, August 7, 2011

Cast from pointer to integer of different size warning - C?

&var is not an integer. It is a pointer. It's type is size_t. On a 32-bit platform, size_t is a 4-byte number, just like an int so there's no problem. But on a 64-bit platform, a size_t is 8 bytes and an int is still only 4 bytes, so you can't actually store a pointer in an int. It will work storing it, but you'll crash the program if you try referencing it.

No comments:

Post a Comment