I am migrating my lib from 32bit to 64bit. The library is written in C. Say for the following API:
void foo(uint32 var)
Do I have to change the type of var to uint64
in any circumstances? What if max of var is not greater than 0xffffffff
?
Do I have to change the type of var to
uint64
in any circumstances? What if max of var is not greater than0xffffffff
?
Nothing says you have to change your datatypes when compiling for 64-bit. The uint32
parameter will behave the same as it did before. (However, you should probably be using uint32_t
from <stdint.h>
if you want to guarantee that your data types work correctly.)
There are a few other places where you want the size of your variables to change, but the behavior will be automatically correct if you use the correct data types:
uintptr_t
This is a pointer-sized integer. So you can cast from void*
to uintptr_t
and back without losing any information. If you instead cast from void*
to uint32_t
, you will corrupt your pointers.off_t
The size of file offsets might change (depending on your toolchain), so you should use this appropriate typedef.