Irving Rabin is a Senior Consultant for Code Integrity Solutions, a consultancy for static source code analysis professional services. Irving is a former architect at Vitria Technologies, Principal Software Engineer at Openwave, and Research and Development Manager at Platinum Technologies.

C and C++ rely heavily on usage of pointers, i.e. variables containing memory addresses. While pointer types are conceptually different from integer types, the physical address is always an integer number. Developers heavily use integer types instead of pointer types in C/C++, even in system headers that come with compilers.

For the last few decades most computer processors used 32-bit memory addresses, so development environments have been built around the assumption that addresses are 32-bit long. Implicit and explicit casting between pointers and integers and overlapping memory structures through pointers or unions became commonplace.

Of course, 32-bit architectures have its limitation; specifically they limit computer memory to 4GB. Application requirements have grown and migration to longer addresses was imminent. While first 64-bit computers have been introduced in the 1970s, only in the mid-1990s did major corporations start releasing 64-bit processors to the market on a larger scale. With a new architecture came the arrival of new operating systems. And, the new architecture brought new meaning and values to the well-known, frequently used legacy types. The most dramatic change was moving to 64-bit pointers. The need to adjust to the new sizes of integer types was apparent.

The Same Rules No Longer Apply

Some of the sizes of the base types changed. Some of them remain the same. However a multitude of implicit assumptions used all over C and C++ code bases suddenly was no longer valid. The code written and tested in 32-bit system was no longer valid with migration to 64-bit computers.

Fortunately, most of the areas where the code may be vulnerable to migration from 32-bit machines to 64-bit machines have been identified and classified. Some of the compilers use aggressive checking techniques to catch possible vulnerabilities expected during migration. Vendors of static analysis tools -- Coverity and Klocwork come to mind -- provide mechanisms that further assist smooth code migration from 32-bit to 64-bit machines. While these tools do not directly address code migration, they provide convenient extensibility and APIs to create customized checkers relevant to 32-bit to 64-bit migration. Augmenting these tools can help even further to uncover and efficiently fix these compatibility problems.

The goal of this article is to help you make your code base architecture-independent, so the same codebase can be built on either a 32-bit machine or 64-bit machine and produce workable code for each machine. Furthermore, if 32-bit programs communicate with 64-bit programs through binary data exchange (through files or sockets), there are ways to make sure that binary structures are immune to migration between the two architecture types.

This article contains detailed analysis and recommendations for dealing with a multitude of issues related to 32-bit to 64-bit migration.