SlideShare a Scribd company logo
1 of 5
Download to read offline
64 bits, Wp64, Visual Studio 2008,
Viva64 and all the rest...
Author: Andrey Karpov

Date: 15.04.2008


Abstract
The purpose of this article is to answer some questions related to safe port of C/C++ code on 64-bit
systems. The article is written as an answer to the topic often discussed on forums and related to the
use of /Wp64 key and Viva64 tool.


Introduction
I am a developer of a static code analyzer Viva64 [1], intended for diagnosing errors in 64-bit programs.
The analyzer integrates into Visual Studio 2005/2008 environment and allows you to check if C/C++ code
is correct according to the set of corresponding rules [2]. Potentially dangerous code sections detected
by Viva64 tool may be analyzed and corrected in time and it reduces costs on testing and maintenance a
lot [3].

While communicating with software developers on forums, via e-mail or at conferences I've noticed that
there are some mistakes which lead to incorrect questions, remarks and comments. Within the limits of
this article I want to try to clarify these points related to the use of 64-bit compilers, /Wp64 key and
static analyzer Viva64. For that I will put several general questions and then answer them. I hope these
answers will help you to better understand 64-bit technologies and find right solutions of different tasks.


1. What is /Wp64 key?
Wp64 key tells the compiler to search possible errors which may occur during compilation of code for
64-bit systems. The check consists in that types marked in 32-bit code by __w64 keyword are
interpreted as 64-bit types.

For example, we have the following code:

typedef int MyInt32;

#ifdef _WIN64

   typedef __int64 MySSizet;

#else

   typedef int MySSizet;

#endif

void foo() {

   MyInt32 value32 = 10;
MySSizet size = 20;

    value32 = size;

}

Expression "value32 = size;" will cause contraction of value and consequently a potential error. We want
to diagnose this case. But during compilation of a 32-bit application everything is correct and we won't
get an warning message

To deal with 64-bit systems we should add /Wp64 key and insert __w64 keyword while defining
MySSizet type in a 32-bit version. As a result the code will look like this:

typedef int MyInt32;

#ifdef _WIN64

    typedef __int64 MySSizet;

#else

    typedef int __w64 MySSizet; // Add __w64 keyword

#endif

void foo() {

    MyInt32 value32 = 10;

    MySSizet size = 20;

    value32 = size; // C4244 64-bit int assigned to 32-bit int

}

Now we'll get an warning message C4244 which will help us to prepare the port of the code on a 64-bit
platform.

Pay attention that /Wp64 key doesn't matter for the 64-bit compilation mode as all the types already
have the necessary size and the compiler will carry the necessary checks. It means that while compiling
the 64-bit version even with /Wp64 key switched off we'll get C4244 message.

That's why, if you regularly compile you code in 64-bit mode you may refuse using /Wp64 in 32-bit code
as in this mode the check is fuller. Besides, diagnosis systems with /Wp64 key is not perfect and often
can cause false response or, just on the contrary, miss of messages. To learn more about this problem
you may see the following links [4, 5].


2. Why do we need Viva64 analyzer if we have /Wp64?
This question is one of the most frequent but it is actually incorrect. Let's at first refer to some analogy.
Modern C/C++ compilers give a lot of messages warning about potential errors. But this doesn't
decrease the urgency of such tools as lint, Gimpel PC-Lint, Parasoft C++test or Abraxas CodeCheck. And
nobody asks what for we need these analyzers if Visual C++ compiler contains /Wp64 key or /Wall key?
The compiler's task is to detect syntax errors in programs and to give messages on the main potential
type errors. The need of the diagnosis's details to be limited is related to the necessity of choosing a
reasonable number of diagnoses that could be useful for all programmers. Another reason is the
requirement that the compiler should be high-performance. Some checks take a lot of time but many
programmers may not need it.

Universal static analyzers allow you to diagnose large classes of potential errors and bad coding style -
that is, everything that is absent in the compiler. The static analyzer's settings are adjusted for concrete
tasks and give detailed information about errors in which a developer is interested. Although static
analyzers are launched regularly they are not launched during compilation of every file being developed.
This allows you to carry rather deep analysis demanding more time. Static analysis is an excellent
methodology among others which help to increase quality and safety of the code.

Similar to this is the situation with checking compatibility of the code with 64-bit systems. We have
briefly discussed what we get with the help of /Wp64 key. This key is a great help for a programmer but
it cannot be useful in every case. Unfortunately, there are much more cases of type errors related to the
use of 64-bit systems. These type errors are described in detail in the article "20 issues of porting C++
code on the 64-bit platform" [6] which I strongly recommend you. It is the great difference in the
number of checks provided by /Wp64 and the number of necessary checks why we need a specialized
tool. Viva64 is such a tool.

There is one more related question: "Some analyzers such as Gimpel PC-Lint or Parasoft C++test support
diagnosis of 64-bit errors. Why do we need Viva64 then?" It's true that these analyzers support
diagnosis of 64-bit errors, but firstly it is not so thorough. For example, some errors related to the
peculiarities of modern C++ language are not taken into consideration. And secondly, these analyzers
work with Unix-systems data models and cannot analyze 64-bit programs developed in Visual Studio
environment. To learn more about all this see "Forgotten problems of development of 64-bit programs"
[7].

Summary: /Wp64 key and other static analyzers don't reduce the need of Viva64.


3. Why is /Wp64 key declared deprecated in Visual Studio 2008?
There is a wrong opinion that /Wp64 key is declared deprecated because diagnosis of 64-bit errors has
become much better in Visual Studio 2008. But it is not so.

/Wp64 key is declared deprecated in Visual Studio 2008 only because it has become unnecessary. The
time to "prepare for 64-bit code" has passed and now it's high time to create 64-bit programs. For that
there is a 64-bit compiler in Visual Studio 2008 (as well as in Visual Studio 2005).

/Wp64 key is useful only in mode of compilation of 32-bit programs. It was created to detect some
errors in time which the program will face in future after migration on 64-bit systems.

During compilation of a 64-bit program /Wp64 key is of no purpose. The compiler of 64-bit applications
carries automatic checks similar to /Wp64 but more accurate. While compiling 32-bit programs /Wp64
mode glitched and it resulted in false error messages. It is not very pleasant and many developers
complained of it and asked to upgrade this mode. Visual C++ developers have acted, in my opinion, very
reasonably. Instead of wasting time on upgrading /Wp64 they declared it outdated. By this they:

    •   encourage programmers to compile their programs with the help of the 64-bit compiler;
•   simplify the system of the compiler's commands (which is overload enough) by removing the
        temporary auxiliary key;
    •   get rid of requests to upgrade this key.


4. Does Viva64 tool remain topical if we switch to Visual Studio 2008?
Yes, it does as nothing has changed. The compiler hasn't changed much what creation of 64-bit
programs is concerned. /Wp64 key in the 32-bit compiler was declared deprecated to stimulate
switching to 64-bit systems but it doesn't concern Viva64. Viva64 analyzer detects much more potential
"64-bit" errors than 64-bit compiler Visual C++ 2005/2008 and is used successfully by many developers.

I would like once more to devote some time to the fight with "evangelists" who propagate that the
compiler can diagnose all the 64-bit errors and that refusing to use /Wp64 key just confirms it.

I ask you to reread the article "20 issues of porting C++ code on the 64-bit platform" [ 6]. Please, think
about it!

The compiler cannot give messages on constructions of the following kind:

unsigned i;

size_t size;

for (i = 0; i != size; i++)

...

Or, for example:

int x, y, z, w, h;

int position = x + y * w + z * w * h;

bigArray[position] = 0.0f;

These are classical widely spread constructions. They are safe in most cases, and developers of
compilers won't introduce warning messages on such constructions although they are potentially
dangerous while porting on 64-bit systems! They should be analyzed at least once. Such errors are
difficult to detect and they occur only in large data arrays or while processing a large number of items.

But all these problems can be easily solved if you look through the code with the help of Viva64. Please,
don't deceive developers convincing them that everything is OK in their programs. You won't do them
any good but may encourage them to switch to 64-bit systems carelessly and thus bring some rare
errors which will occur only when a program will be launched..


Conclusions
    1. /Wp64 key is useful but not sufficient at all to guarantee that a 64-bit program will work.
    2. For deeper analysis of 64-bit code one should use static analyzers providing corresponding
       checks.
    3. The specialized Viva64 tool is the best solution to check C/C++ code for the 64-bit versions of
       Windows.
References
  1. Evgeniy Ryzhkov. Viva64: what is it and for whom is it meant?
  2. http://www.viva64.com/art-1-2-903037923.html
  3. Andrey Karpov, Evgeniy Ryzhkov. Static code analysis for verification of 64-bit applications.
     http://www.viva64.com/art-1-2-184080346.html
  4. Andrey Karpov. Problems of testing 64-bit applications.
  5. http://www.viva64.com/art-1-2-1289354852.html
  6. Keith Brown, SetWindowLongPtr and /Wp64. http://www.viva64.com/go.php?url=66.
  7. MSDN Forum, http://www.viva64.com/go.php?url=67
  8. Andrey Karpov, Evgeniy Ryzhkov. 20 Issues of Porting C++ Code on the 64-bit Platform.
     http://www.viva64.com/art-1-2-599168895.html
  9. Andrey Karpov. Forgotten problems of 64-bit programs development.
     http://www.viva64.com/art-1-2-16511733.html

More Related Content

What's hot

What's hot (7)

Static analysis as part of the development process in Unreal Engine
Static analysis as part of the development process in Unreal EngineStatic analysis as part of the development process in Unreal Engine
Static analysis as part of the development process in Unreal Engine
 
Analysis of PascalABC.NET using SonarQube plugins: SonarC# and PVS-Studio
Analysis of PascalABC.NET using SonarQube plugins: SonarC# and PVS-StudioAnalysis of PascalABC.NET using SonarQube plugins: SonarC# and PVS-Studio
Analysis of PascalABC.NET using SonarQube plugins: SonarC# and PVS-Studio
 
Comparing static analysis in Visual Studio 2012 (Visual C++ 2012) and PVS-Studio
Comparing static analysis in Visual Studio 2012 (Visual C++ 2012) and PVS-StudioComparing static analysis in Visual Studio 2012 (Visual C++ 2012) and PVS-Studio
Comparing static analysis in Visual Studio 2012 (Visual C++ 2012) and PVS-Studio
 
Lesson 26. Optimization of 64-bit programs
Lesson 26. Optimization of 64-bit programsLesson 26. Optimization of 64-bit programs
Lesson 26. Optimization of 64-bit programs
 
Safety on the Max: How to Write Reliable C/C++ Code for Embedded Systems
Safety on the Max: How to Write Reliable C/C++ Code for Embedded SystemsSafety on the Max: How to Write Reliable C/C++ Code for Embedded Systems
Safety on the Max: How to Write Reliable C/C++ Code for Embedded Systems
 
New Year PVS-Studio 6.00 Release: Scanning Roslyn
New Year PVS-Studio 6.00 Release: Scanning RoslynNew Year PVS-Studio 6.00 Release: Scanning Roslyn
New Year PVS-Studio 6.00 Release: Scanning Roslyn
 
Parallel Lint
Parallel LintParallel Lint
Parallel Lint
 

Similar to 64 bits, Wp64, Visual Studio 2008, Viva64 and all the rest...

Similar to 64 bits, Wp64, Visual Studio 2008, Viva64 and all the rest... (20)

Lesson 6. Errors in 64-bit code
Lesson 6. Errors in 64-bit codeLesson 6. Errors in 64-bit code
Lesson 6. Errors in 64-bit code
 
Viva64: What Is It, and Who Is It for?
Viva64: What Is It, and Who Is It for?Viva64: What Is It, and Who Is It for?
Viva64: What Is It, and Who Is It for?
 
A Collection of Examples of 64-bit Errors in Real Programs
A Collection of Examples of 64-bit Errors in Real ProgramsA Collection of Examples of 64-bit Errors in Real Programs
A Collection of Examples of 64-bit Errors in Real Programs
 
A Collection of Examples of 64-bit Errors in Real Programs
A Collection of Examples of 64-bit Errors in Real ProgramsA Collection of Examples of 64-bit Errors in Real Programs
A Collection of Examples of 64-bit Errors in Real Programs
 
Seven Steps of Migrating a Program to a 64-bit System
Seven Steps of Migrating a Program to a 64-bit SystemSeven Steps of Migrating a Program to a 64-bit System
Seven Steps of Migrating a Program to a 64-bit System
 
Seven Steps of Migrating a Program to a 64-bit System
Seven Steps of Migrating a Program to a 64-bit SystemSeven Steps of Migrating a Program to a 64-bit System
Seven Steps of Migrating a Program to a 64-bit System
 
PVS-Studio advertisement - static analysis of C/C++ code
PVS-Studio advertisement - static analysis of C/C++ codePVS-Studio advertisement - static analysis of C/C++ code
PVS-Studio advertisement - static analysis of C/C++ code
 
Monitoring a program that monitors computer networks
Monitoring a program that monitors computer networksMonitoring a program that monitors computer networks
Monitoring a program that monitors computer networks
 
Driver Development for Windows 64-bit
Driver Development for Windows 64-bitDriver Development for Windows 64-bit
Driver Development for Windows 64-bit
 
The forgotten problems of 64-bit programs development
The forgotten problems of 64-bit programs developmentThe forgotten problems of 64-bit programs development
The forgotten problems of 64-bit programs development
 
64-bit
64-bit64-bit
64-bit
 
Lesson 7. The issues of detecting 64-bit errors
Lesson 7. The issues of detecting 64-bit errorsLesson 7. The issues of detecting 64-bit errors
Lesson 7. The issues of detecting 64-bit errors
 
PVS-Studio, a solution for developers of modern resource-intensive applications
PVS-Studio, a solution for developers of modern resource-intensive applicationsPVS-Studio, a solution for developers of modern resource-intensive applications
PVS-Studio, a solution for developers of modern resource-intensive applications
 
Introduction into 64 bits for the beginners or where's again the 64-bit world?
Introduction into 64 bits for the beginners or where's again the 64-bit world?Introduction into 64 bits for the beginners or where's again the 64-bit world?
Introduction into 64 bits for the beginners or where's again the 64-bit world?
 
A collection of examples of 64 bit errors in real programs
A collection of examples of 64 bit errors in real programsA collection of examples of 64 bit errors in real programs
A collection of examples of 64 bit errors in real programs
 
Comparing capabilities of PVS-Studio and Visual Studio 2010 in detecting defe...
Comparing capabilities of PVS-Studio and Visual Studio 2010 in detecting defe...Comparing capabilities of PVS-Studio and Visual Studio 2010 in detecting defe...
Comparing capabilities of PVS-Studio and Visual Studio 2010 in detecting defe...
 
A Long-Awaited Check of Unreal Engine 4
A Long-Awaited Check of Unreal Engine 4A Long-Awaited Check of Unreal Engine 4
A Long-Awaited Check of Unreal Engine 4
 
Comparing PVS-Studio with other code analyzers
Comparing PVS-Studio with other code analyzersComparing PVS-Studio with other code analyzers
Comparing PVS-Studio with other code analyzers
 
Safety of 64-bit code
Safety of 64-bit codeSafety of 64-bit code
Safety of 64-bit code
 
64-Bit Code in 2015: New in the Diagnostics of Possible Issues
64-Bit Code in 2015: New in the Diagnostics of Possible Issues64-Bit Code in 2015: New in the Diagnostics of Possible Issues
64-Bit Code in 2015: New in the Diagnostics of Possible Issues
 

More from Andrey Karpov

More from Andrey Karpov (20)

60 антипаттернов для С++ программиста
60 антипаттернов для С++ программиста60 антипаттернов для С++ программиста
60 антипаттернов для С++ программиста
 
60 terrible tips for a C++ developer
60 terrible tips for a C++ developer60 terrible tips for a C++ developer
60 terrible tips for a C++ developer
 
Ошибки, которые сложно заметить на code review, но которые находятся статичес...
Ошибки, которые сложно заметить на code review, но которые находятся статичес...Ошибки, которые сложно заметить на code review, но которые находятся статичес...
Ошибки, которые сложно заметить на code review, но которые находятся статичес...
 
PVS-Studio in 2021 - Error Examples
PVS-Studio in 2021 - Error ExamplesPVS-Studio in 2021 - Error Examples
PVS-Studio in 2021 - Error Examples
 
PVS-Studio in 2021 - Feature Overview
PVS-Studio in 2021 - Feature OverviewPVS-Studio in 2021 - Feature Overview
PVS-Studio in 2021 - Feature Overview
 
PVS-Studio в 2021 - Примеры ошибок
PVS-Studio в 2021 - Примеры ошибокPVS-Studio в 2021 - Примеры ошибок
PVS-Studio в 2021 - Примеры ошибок
 
PVS-Studio в 2021
PVS-Studio в 2021PVS-Studio в 2021
PVS-Studio в 2021
 
Make Your and Other Programmer’s Life Easier with Static Analysis (Unreal Eng...
Make Your and Other Programmer’s Life Easier with Static Analysis (Unreal Eng...Make Your and Other Programmer’s Life Easier with Static Analysis (Unreal Eng...
Make Your and Other Programmer’s Life Easier with Static Analysis (Unreal Eng...
 
Best Bugs from Games: Fellow Programmers' Mistakes
Best Bugs from Games: Fellow Programmers' MistakesBest Bugs from Games: Fellow Programmers' Mistakes
Best Bugs from Games: Fellow Programmers' Mistakes
 
Does static analysis need machine learning?
Does static analysis need machine learning?Does static analysis need machine learning?
Does static analysis need machine learning?
 
Typical errors in code on the example of C++, C#, and Java
Typical errors in code on the example of C++, C#, and JavaTypical errors in code on the example of C++, C#, and Java
Typical errors in code on the example of C++, C#, and Java
 
How to Fix Hundreds of Bugs in Legacy Code and Not Die (Unreal Engine 4)
How to Fix Hundreds of Bugs in Legacy Code and Not Die (Unreal Engine 4)How to Fix Hundreds of Bugs in Legacy Code and Not Die (Unreal Engine 4)
How to Fix Hundreds of Bugs in Legacy Code and Not Die (Unreal Engine 4)
 
Game Engine Code Quality: Is Everything Really That Bad?
Game Engine Code Quality: Is Everything Really That Bad?Game Engine Code Quality: Is Everything Really That Bad?
Game Engine Code Quality: Is Everything Really That Bad?
 
C++ Code as Seen by a Hypercritical Reviewer
C++ Code as Seen by a Hypercritical ReviewerC++ Code as Seen by a Hypercritical Reviewer
C++ Code as Seen by a Hypercritical Reviewer
 
The Use of Static Code Analysis When Teaching or Developing Open-Source Software
The Use of Static Code Analysis When Teaching or Developing Open-Source SoftwareThe Use of Static Code Analysis When Teaching or Developing Open-Source Software
The Use of Static Code Analysis When Teaching or Developing Open-Source Software
 
Static Code Analysis for Projects, Built on Unreal Engine
Static Code Analysis for Projects, Built on Unreal EngineStatic Code Analysis for Projects, Built on Unreal Engine
Static Code Analysis for Projects, Built on Unreal Engine
 
The Great and Mighty C++
The Great and Mighty C++The Great and Mighty C++
The Great and Mighty C++
 
Static code analysis: what? how? why?
Static code analysis: what? how? why?Static code analysis: what? how? why?
Static code analysis: what? how? why?
 
Zero, one, two, Freddy's coming for you
Zero, one, two, Freddy's coming for youZero, one, two, Freddy's coming for you
Zero, one, two, Freddy's coming for you
 
PVS-Studio Is Now in Chocolatey: Checking Chocolatey under Azure DevOps
PVS-Studio Is Now in Chocolatey: Checking Chocolatey under Azure DevOpsPVS-Studio Is Now in Chocolatey: Checking Chocolatey under Azure DevOps
PVS-Studio Is Now in Chocolatey: Checking Chocolatey under Azure DevOps
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 

64 bits, Wp64, Visual Studio 2008, Viva64 and all the rest...

  • 1. 64 bits, Wp64, Visual Studio 2008, Viva64 and all the rest... Author: Andrey Karpov Date: 15.04.2008 Abstract The purpose of this article is to answer some questions related to safe port of C/C++ code on 64-bit systems. The article is written as an answer to the topic often discussed on forums and related to the use of /Wp64 key and Viva64 tool. Introduction I am a developer of a static code analyzer Viva64 [1], intended for diagnosing errors in 64-bit programs. The analyzer integrates into Visual Studio 2005/2008 environment and allows you to check if C/C++ code is correct according to the set of corresponding rules [2]. Potentially dangerous code sections detected by Viva64 tool may be analyzed and corrected in time and it reduces costs on testing and maintenance a lot [3]. While communicating with software developers on forums, via e-mail or at conferences I've noticed that there are some mistakes which lead to incorrect questions, remarks and comments. Within the limits of this article I want to try to clarify these points related to the use of 64-bit compilers, /Wp64 key and static analyzer Viva64. For that I will put several general questions and then answer them. I hope these answers will help you to better understand 64-bit technologies and find right solutions of different tasks. 1. What is /Wp64 key? Wp64 key tells the compiler to search possible errors which may occur during compilation of code for 64-bit systems. The check consists in that types marked in 32-bit code by __w64 keyword are interpreted as 64-bit types. For example, we have the following code: typedef int MyInt32; #ifdef _WIN64 typedef __int64 MySSizet; #else typedef int MySSizet; #endif void foo() { MyInt32 value32 = 10;
  • 2. MySSizet size = 20; value32 = size; } Expression "value32 = size;" will cause contraction of value and consequently a potential error. We want to diagnose this case. But during compilation of a 32-bit application everything is correct and we won't get an warning message To deal with 64-bit systems we should add /Wp64 key and insert __w64 keyword while defining MySSizet type in a 32-bit version. As a result the code will look like this: typedef int MyInt32; #ifdef _WIN64 typedef __int64 MySSizet; #else typedef int __w64 MySSizet; // Add __w64 keyword #endif void foo() { MyInt32 value32 = 10; MySSizet size = 20; value32 = size; // C4244 64-bit int assigned to 32-bit int } Now we'll get an warning message C4244 which will help us to prepare the port of the code on a 64-bit platform. Pay attention that /Wp64 key doesn't matter for the 64-bit compilation mode as all the types already have the necessary size and the compiler will carry the necessary checks. It means that while compiling the 64-bit version even with /Wp64 key switched off we'll get C4244 message. That's why, if you regularly compile you code in 64-bit mode you may refuse using /Wp64 in 32-bit code as in this mode the check is fuller. Besides, diagnosis systems with /Wp64 key is not perfect and often can cause false response or, just on the contrary, miss of messages. To learn more about this problem you may see the following links [4, 5]. 2. Why do we need Viva64 analyzer if we have /Wp64? This question is one of the most frequent but it is actually incorrect. Let's at first refer to some analogy. Modern C/C++ compilers give a lot of messages warning about potential errors. But this doesn't decrease the urgency of such tools as lint, Gimpel PC-Lint, Parasoft C++test or Abraxas CodeCheck. And nobody asks what for we need these analyzers if Visual C++ compiler contains /Wp64 key or /Wall key?
  • 3. The compiler's task is to detect syntax errors in programs and to give messages on the main potential type errors. The need of the diagnosis's details to be limited is related to the necessity of choosing a reasonable number of diagnoses that could be useful for all programmers. Another reason is the requirement that the compiler should be high-performance. Some checks take a lot of time but many programmers may not need it. Universal static analyzers allow you to diagnose large classes of potential errors and bad coding style - that is, everything that is absent in the compiler. The static analyzer's settings are adjusted for concrete tasks and give detailed information about errors in which a developer is interested. Although static analyzers are launched regularly they are not launched during compilation of every file being developed. This allows you to carry rather deep analysis demanding more time. Static analysis is an excellent methodology among others which help to increase quality and safety of the code. Similar to this is the situation with checking compatibility of the code with 64-bit systems. We have briefly discussed what we get with the help of /Wp64 key. This key is a great help for a programmer but it cannot be useful in every case. Unfortunately, there are much more cases of type errors related to the use of 64-bit systems. These type errors are described in detail in the article "20 issues of porting C++ code on the 64-bit platform" [6] which I strongly recommend you. It is the great difference in the number of checks provided by /Wp64 and the number of necessary checks why we need a specialized tool. Viva64 is such a tool. There is one more related question: "Some analyzers such as Gimpel PC-Lint or Parasoft C++test support diagnosis of 64-bit errors. Why do we need Viva64 then?" It's true that these analyzers support diagnosis of 64-bit errors, but firstly it is not so thorough. For example, some errors related to the peculiarities of modern C++ language are not taken into consideration. And secondly, these analyzers work with Unix-systems data models and cannot analyze 64-bit programs developed in Visual Studio environment. To learn more about all this see "Forgotten problems of development of 64-bit programs" [7]. Summary: /Wp64 key and other static analyzers don't reduce the need of Viva64. 3. Why is /Wp64 key declared deprecated in Visual Studio 2008? There is a wrong opinion that /Wp64 key is declared deprecated because diagnosis of 64-bit errors has become much better in Visual Studio 2008. But it is not so. /Wp64 key is declared deprecated in Visual Studio 2008 only because it has become unnecessary. The time to "prepare for 64-bit code" has passed and now it's high time to create 64-bit programs. For that there is a 64-bit compiler in Visual Studio 2008 (as well as in Visual Studio 2005). /Wp64 key is useful only in mode of compilation of 32-bit programs. It was created to detect some errors in time which the program will face in future after migration on 64-bit systems. During compilation of a 64-bit program /Wp64 key is of no purpose. The compiler of 64-bit applications carries automatic checks similar to /Wp64 but more accurate. While compiling 32-bit programs /Wp64 mode glitched and it resulted in false error messages. It is not very pleasant and many developers complained of it and asked to upgrade this mode. Visual C++ developers have acted, in my opinion, very reasonably. Instead of wasting time on upgrading /Wp64 they declared it outdated. By this they: • encourage programmers to compile their programs with the help of the 64-bit compiler;
  • 4. simplify the system of the compiler's commands (which is overload enough) by removing the temporary auxiliary key; • get rid of requests to upgrade this key. 4. Does Viva64 tool remain topical if we switch to Visual Studio 2008? Yes, it does as nothing has changed. The compiler hasn't changed much what creation of 64-bit programs is concerned. /Wp64 key in the 32-bit compiler was declared deprecated to stimulate switching to 64-bit systems but it doesn't concern Viva64. Viva64 analyzer detects much more potential "64-bit" errors than 64-bit compiler Visual C++ 2005/2008 and is used successfully by many developers. I would like once more to devote some time to the fight with "evangelists" who propagate that the compiler can diagnose all the 64-bit errors and that refusing to use /Wp64 key just confirms it. I ask you to reread the article "20 issues of porting C++ code on the 64-bit platform" [ 6]. Please, think about it! The compiler cannot give messages on constructions of the following kind: unsigned i; size_t size; for (i = 0; i != size; i++) ... Or, for example: int x, y, z, w, h; int position = x + y * w + z * w * h; bigArray[position] = 0.0f; These are classical widely spread constructions. They are safe in most cases, and developers of compilers won't introduce warning messages on such constructions although they are potentially dangerous while porting on 64-bit systems! They should be analyzed at least once. Such errors are difficult to detect and they occur only in large data arrays or while processing a large number of items. But all these problems can be easily solved if you look through the code with the help of Viva64. Please, don't deceive developers convincing them that everything is OK in their programs. You won't do them any good but may encourage them to switch to 64-bit systems carelessly and thus bring some rare errors which will occur only when a program will be launched.. Conclusions 1. /Wp64 key is useful but not sufficient at all to guarantee that a 64-bit program will work. 2. For deeper analysis of 64-bit code one should use static analyzers providing corresponding checks. 3. The specialized Viva64 tool is the best solution to check C/C++ code for the 64-bit versions of Windows.
  • 5. References 1. Evgeniy Ryzhkov. Viva64: what is it and for whom is it meant? 2. http://www.viva64.com/art-1-2-903037923.html 3. Andrey Karpov, Evgeniy Ryzhkov. Static code analysis for verification of 64-bit applications. http://www.viva64.com/art-1-2-184080346.html 4. Andrey Karpov. Problems of testing 64-bit applications. 5. http://www.viva64.com/art-1-2-1289354852.html 6. Keith Brown, SetWindowLongPtr and /Wp64. http://www.viva64.com/go.php?url=66. 7. MSDN Forum, http://www.viva64.com/go.php?url=67 8. Andrey Karpov, Evgeniy Ryzhkov. 20 Issues of Porting C++ Code on the 64-bit Platform. http://www.viva64.com/art-1-2-599168895.html 9. Andrey Karpov. Forgotten problems of 64-bit programs development. http://www.viva64.com/art-1-2-16511733.html