C++ Builder, 64-bit software build and Viva64 renaissance
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.
This is just a common error in a program. But it has one peculiar feature: it reveals itself only in 64-bit programs . 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:
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.
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 . But it often doesn’t happen in practice.
The slow-down may be caused by several reasons:
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 ; 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.
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:
I wish you bugless 64-bit software.
|All times are GMT +5.5. The time now is 13:40.|