Typical errors of porting C++ code on the 64-bit platform


The text is an abridged variant of "20 issues of porting C++ code on the 64-bit platform" article. If you are interested in the topic of porting programs to 64-bit systems, you can find a full version of the article here.

 We offer you to read the article devoted to the port of the program code of 32-bit applications on 64-bit systems. The article is written for programmers who use C++ but it may be also useful for all who face the port of applications on other platforms.

One should understand properly that the new class of errors which appears while writing 64-bit programs is not just some new incorrect constructions among thousands of others. These are inevitable difficulties which the developers of any developing program will face. This article will help you to be ready for these difficulties and will show the ways to overcome them. Besides advantages, any new technology (in programming and other spheres as well) carries some limitations and even problems of using this technology. The same situation can be found in the sphere of developing 64-bit software. We all know that 64-bit software is the next step of the information technologies development. But in reality, only few programmers have faced the nuances of this sphere and developing 64-bit programs in particular.

We won’t dwell on the advantages which the use of 64-bit architecture opens before programmers. There are a lot of publications devoted to this theme and the reader can find them easily.

The aim of this article is to observe thoroughly those problems which the developer of 64-bit programs can face. In the article you will learn about:

The aim of this article is to observe thoroughly those problems which the developer of 64-bit programs can face. In the article you will learn about:

  • typical errors of programming which occur on 64-bit systems;
  • the reasons for appearing of these errors and the corresponding examples;
  • methods of correcting the listed errors;
  • the review of methods and means of searching errors in 64-bit programs.

The given information will allow you:

  • to learn the differences between 32-bit and 64-bit systems;
  • to avoid errors while writing the code for 64-bit systems;
  • to speed up the process of migration of a 32-bit application on the 64-bit architecture with the help of the great reducing of the time of debugging and testing;
  • to forecast the time of porting the code on the 64-bit system more accurately and seriously.

There are a lot of examples given in the article which you should try in the programming environment for better understanding. Going into them you will get something more than just an addition of separate elements. You will open the door into the world of 64-bit systems.

We’ll use term "memsize" type in the text. By this we’ll understand any simple integer type which is capable to keep a pointer and changes its size according to the change of the platform dimension form 32-bit to 64-bit. The examples memsize types: size_t, ptrdiff_t, all pointers, intptr_t, INT_PTR, DWORD_PTR.

We should say some words about the data models which determine the correspondence of the sizes of fundamental types for different systems. Table N1 contains data models which can interest us.

                      ILP32  LP64  LLP64  ILP64
char                    8      8      8      8
short                  16     16     16     16
int                    32     32     32     64
long                   32     64     32     64
long long              64     64     64     64
size_t, ptrdiff_t      32     64     64     64
pointer                32     64     64     64

On default in this article we’ll consider that the program port will be fulfilled from the system with the data model ILP32 on systems with data model LP64 or LLP64.

And finally, 64-bit model in Linux (LP64) differs from that in Windows (LLP64) only in the size of long type. So long as it is their only difference, to summarize the account we’ll avoid using long, unsigned long types, and will use ptrdiff_t, size_t types.

Let’s start observing the type errors which occur while porting programs on the 64-bit architecture.

You might also like...



Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“An expert is a man who has made all the mistakes that can be made in a very narrow field” - Niels Bohr