To get a trial key
fill out the form below
Team License (a basic version)
Enterprise License (extended version)
* By clicking this button you agree to our Privacy Policy statement

Request our prices
New License
License Renewal
--Select currency--
* By clicking this button you agree to our Privacy Policy statement

Free PVS-Studio license for Microsoft MVP specialists
* By clicking this button you agree to our Privacy Policy statement

To get the licence for your open-source project, please fill out this form
* By clicking this button you agree to our Privacy Policy statement

I am interested to try it on the platforms:
* By clicking this button you agree to our Privacy Policy statement

Message submitted.

Your message has been sent. We will email you at

If you haven't received our response, please do the following:
check your Spam/Junk folder and click the "Not Spam" button for our message.
This way, you won't miss messages from our team in the future.

C++Builder, 64-bit software build and V…

C++Builder, 64-bit software build and Viva64 renaissance

Feb 01 2013

After a long wait C++Builder XE3 Update 1 has finally acquired the capability of building 64-bit applications. It means that developers using this tool will soon face the yet unfamiliar world of 64-bit errors.

C++ Builder support in PVS-Studio had been dropped after version 5.20. If you have any questions, feel free to contact our support.

What is a 64-bit error?

This is just a common error in a program. But it has one peculiar feature: it reveals itself only in 64-bit programs [1]. At the same time, you won't find this error when building the 32-bit version of the program. Here is a very simple example to start with:

float *buf = (float *)malloc(1000 * sizeof(float));
unsigned X = (unsigned)buf;
float *p = (float *)X;

The pointer is being stored for some time in a variable of the unsigned int type. The pointer will become 64-bit in the 64-bit program, while the unsigned type will still be 32-bit. As a result, high-order bits will be lost, which will cause unpredictable results of program execution. The error is even more insidious due to the fact that it will rarely occur in the 64-bit program. The problem will be revealed only when memory is allocated outside the first 4 Gbytes of the address space.

The 64-bit error shown above is simple and not of much interest. Any compiler will warn you about a dangerous type conversion like that. Let's study a more interesting issue.

float *Array = (float *)malloc(1000 * sizeof(float));
float *p = Array + 500;
unsigned A = 3;
int B = -5;
p[A + B] = 1.0f;

The code will work in the 32-bit program but cause a crash in the 64-bit one. The reason is that the "A + B" expression has the unsigned int type. It will equal 0xFFFFFFFEu. It is incorrect in any case of course; but in a 32-bit system an overflow will occur when adding the pointer to the number and, as a result, the 32-bit program will continue working despite the error.

This defect is harder to find than the previous one. Most compilers think that the code contains nothing suspicious. They won't notice anything odd in the following code either:

size_t Count = BigValue;
for (unsigned Index = 0; Index != Count; Index++)
{ ... }

If the value of the Count variable is higher than UINT_MAX in the 64-bit program, an infinite loop will occur.

All this is just a tip of the iceberg. There are 64-bit errors caused by using magic numbers in code (4, 32, 0xFFFFFFFF), errors of virtual function declaration, and so on. You can study various patterns of 64-bit errors in detail in the following article "A Collection of Examples of 64-bit Errors".

Subtleties and nuances of 64-bit code optimization

Besides errors you may face another unexpected and unpleasant thing: lower performance of the 64-bit version of your program compared to the 32-bit one. In fact, the 64-bit program should work faster [2]. But it often doesn't happen in practice.

The slow-down may be caused by several reasons:

  • Inappropriate types are used as array indexes. It causes a lot of senseless type conversions.
  • Inappropriate types are used to store data. Because of the increase of array sizes the amount of memory being consumed may grow twice. As a result, there will be more cache misses and the time of data passing through the bus will grow.
  • Increase of structure sizes because of alignment changes. It also causes increase of memory amount being used.

What's to be done?

Now you have learned that preparing the 64-bit version of your program consists not only of code recompilation. You may face strange errors and performance losses.

It's outside the scope of this article to describe methods of avoiding 64-bit errors. The point is that the nuances are too numerous and can't be described in one article. That's why I have to refer you to another source.

Several years ago we wrote a large guide on 64-bit software development. It describes in detail all the patterns of 64-bit errors, ways of optimizing a 64-bit program, and points to consider when creating tests for such programs.

Lessons on development of 64-bit C/C++ applications

Many developers using Visual C++ are familiar with these materials. Now, I believe, they will become useful to those who use the C++Builder compiler too. The section contains information of general kind and will be useful regardless of tools you use.


Information given in the guide is enough to help you write correct 64-bit programs. But it won't be of much aid if you need to port a large software project to a 64-bit system. It's impossible to review the whole code and find all the dangerous fragments.

The PVS-Studio static analyzer has a set of diagnostic rules called Viva64 to solve this issue. This is the most complete set for detecting 64-bit errors among those existing nowadays.

Now that PVS-Studio has become available in the C++Builder environment, programmers will spend less time and effort on porting their codes. Yes, it's hard to check all the diagnostic messages, but it's, first, better than spending a lot of time catching strange and badly reproducible errors [3]; and, second, the PVS-Studio analyzer has a highly developed system of suppressing false positives, and we can always give you tips on how to customize it.

Here you can download a full-function demo version of PVS-Studio. By the time of writing this article the analyzer can integrate into Embarcadero RAD Studio XE2 and XE3 (including Update 1). We will perhaps support other versions in future too.

Preparation for code porting

Taking an old project and trying to build its 64-bit version is actually a thankless task. That's why many developers using C++Builder would like to do it gradually. You should prepare your code at first and only then start trying to compile its 64-bit version. The PVS-Studio analyzer will help you eliminate most of 64-bit errors beforehand: it can check 32-bit projects as well as 64-bit ones.

But keep in mind that a truly complete analysis is possible only with a 64-bit project. There are many things that make detection of 64-bit defects in 32-bit projects difficult. Preprocessor directives are the most obvious example. If some code fragment is not compiled in the 32-bit program, it won't therefore be checked and no errors will be found in it.


Besides the links given in the article I would like to recommend you to visit some other sections of our website:

  • Reviews of articles on 64-bit software development.
  • Knowledge base (it mostly concerns 64-bit software development).
  • Twitter with news on the subjects of the C++ language, 64-bit software development, and so on.

I wish you bugless 64-bit software.


Popular related articles
Appreciate Static Code Analysis!

Date: Oct 16 2017

Author: Andrey Karpov

I am really astonished by the capabilities of static code analysis even though I am one of the developers of PVS-Studio analyzer myself. The tool surprised me the other day as it turned out to be sma…
How PVS-Studio Proved to Be More Attentive Than Three and a Half Programmers

Date: Oct 22 2018

Author: Andrey Karpov

Just like other static analyzers, PVS-Studio often produces false positives. What you are about to read is a short story where I'll tell you how PVS-Studio proved, just one more time, to be more atte…
The Evil within the Comparison Functions

Date: May 19 2017

Author: Andrey Karpov

Perhaps, readers remember my article titled "Last line effect". It describes a pattern I've once noticed: in most cases programmers make an error in the last line of similar text blocks. Now I want t…
Characteristics of PVS-Studio Analyzer by the Example of EFL Core Libraries, 10-15% of False Positives

Date: Jul 31 2017

Author: Andrey Karpov

After I wrote quite a big article about the analysis of the Tizen OS code, I received a large number of questions concerning the percentage of false positives and the density of errors (how many erro…
Free PVS-Studio for those who develops open source projects

Date: Dec 22 2018

Author: Andrey Karpov

On the New 2019 year's eve, a PVS-Studio team decided to make a nice gift for all contributors of open-source projects hosted on GitHub, GitLab or Bitbucket. They are given free usage of PVS-Studio s…
Technologies used in the PVS-Studio code analyzer for finding bugs and potential vulnerabilities

Date: Nov 21 2018

Author: Andrey Karpov

A brief description of technologies used in the PVS-Studio tool, which let us effectively detect a large number of error patterns and potential vulnerabilities. The article describes the implementati…
The way static analyzers fight against false positives, and why they do it

Date: Mar 20 2017

Author: Andrey Karpov

In my previous article I wrote that I don't like the approach of evaluating the efficiency of static analyzers with the help of synthetic tests. In that article, I give the example of a code fragment…
Static analysis as part of the development process in Unreal Engine

Date: Jun 27 2017

Author: Andrey Karpov

Unreal Engine continues to develop as new code is added and previously written code is changed. What is the inevitable consequence of ongoing development in a project? The emergence of new bugs in th…
PVS-Studio for Java

Date: Jan 17 2019

Author: Andrey Karpov

In the seventh version of the PVS-Studio static analyzer, we added support of the Java language. It's time for a brief story of how we've started making support of the Java language, how far we've co…
The Ultimate Question of Programming, Refactoring, and Everything

Date: Apr 14 2016

Author: Andrey Karpov

Yes, you've guessed correctly - the answer is "42". In this article you will find 42 recommendations about coding in C++ that can help a programmer avoid a lot of errors, save time and effort. The au…

Comments (0)

Next comments
This website uses cookies and other technology to provide you a more personalized experience. By continuing the view of our web-pages you accept the terms of using these files. If you don't want your personal data to be processed, please, leave this site.
Learn More →