I am presently working on converting a 32bits application into a 64bits application in C. This application is currently working on x86 architecture (Windows, osx, Unix, Linu
One potential problem not already mentioned is that if your app reads or writes binary data from disk (e.g., read an array of structs using fread
), you are going to have to check very carefully and perhaps wind up having two readers: one for legacy files and one for 64-bit files. Or, if you are careful to use types like uint32_t
and so on from the <stdint.h>
header file, you can redefine your structs to be bit-for-bit compatible. In any case, binary I/O is a thing to watch out for.
Well, fundamentally, the number of changes are fairly small, but it'll still be a major task if the application isn't carefully written to be somewhat portable to begin with.
The main difference is that pointers are 64 bit wide, but most other datatypes are unchanged. An int is still 32 bit, and a long is probably also still 32 bit. So if your code casts between ints and pointers, that's going to break. Similarly, any struct or similar which depends on a specific offset to a member may break because other members may now be bigger, and so change the offset.
Of course, your code should never rely on these tricks in the first place, so in an ideal world, this wouldn't be a problem at all, and you could simply recompile and everything would work. But you probably don't live in an ideal world... ;)
All about 64-bit for developers:
Articles about 64-bit Development
Links collection 64-bit Resources
Tool Viva64
There are lots of good answers already.
Consider using Gimpel Lint. It can point out exactly the types of constructs that are problematic. If your experience is like mine, it will also show you lots of bugs in the system unrelated to the 32/64 bit port.
LONG
is not long
.(int)&x
casts and typing with intptr_t
and (unsigned int)&x
with uintptr_t
char*
to do pointer arithmetic with it.4 = sizeof(void*)
#ifdef RUN64
or anything similar. You'll regret it if 128-bit platforms ever go into vogue.EDIT added uintptr_t
note as suggested by comment.
If you used the correct types for your values - eg. size_t
, ptrdiff_t
, uintptr_t
, the fixed sized int types from stdint.h
where appropriate - and did not hardcode value sizes, your code should work out of the box.