Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding 64 bit support to existing 32 bit code, is it difficult?

There is a library which I build against different 32-bit platforms. Now, 64-bit architectures must be supported. What are the most general strategies to extend existing 32-bit code to support 64-bit architectures? Should I use #ifdef's or anything else?

like image 354
psihodelia Avatar asked Nov 02 '10 13:11

psihodelia


1 Answers

The amount of effort involved will depend entirely on how well written the original code is. In the best possible case there will be no effort involved other than re-compiling. In the worst case you will have to spend a lot of time making your code "64 bit clean".

Typical problems are:

  • assumptions about sizes of int/long/pointer/etc
  • assigning pointers <=> ints
  • relying on default argument or function result conversions (i.e. no function prototypes)
  • inappropriate printf/scanf format specifiers
  • assumptions about size/alignment/padding of structs (particularly in regard to file or network I/O, or interfacing with other APIs, etc)
  • inappropriate casts when doing pointer arithmetic with byte offsets
like image 80
Paul R Avatar answered Oct 21 '22 04:10

Paul R