Go back to blog listing

Porting to 64-Bit Platforms: Why Is it So Challenging?

64bit

Most developers responsible for porting C/C++ code to 64-bit processors—or to any new hardware, for that matter—find that memory problems seem to multiply when they reach the new platform or architecture.

The fundamental problem with the transition to 64-bit architectures is that assumptions about the size in bits of the various integral and pointer types are no longer true. For instance:

  • Coding constructs that are potentially problematic are implicit conversions from long to int by assignment and explicit casts. The former will most likely cause compilers to issue a warning; the latter, on the other hand, will be accepted silently, leading to all sorts of problems that will not surface until runtime.
  • Integer constants that are not explicitly sized are assumed to be int’s. This is of some concern for mixing signed and unsigned constants. Proper use of the relevant suffixes should alleviate such problems.

Other major sources of trouble are the various types of pointer incompatibilities. For example, on most 64-bit architectures, a pointer no longer will fit inside an int and code that stores pointer values inside int variables will no longer function properly.

These and other problems are typically exposed during porting because porting is essentially a type of mutation testing. When you port code, you essentially create what can be called an “equivalent mutant”—a version of the original code with minor changes that should not affect the outcomes of your test cases.   However, creating and running these equivalent mutants tends to expose many strange errors—such as errors related to copy constructors, constructors, initialization, and pointers.

In the next few entries, I'll take a closer look at how runtime error detection, static code analysis, and unit testing can be used to prepare for porting, then introduce a strategy for efficiently identifying errors on the 64-bit processor.

***

Photo Credit: jurvetson

Stay up to date