Library tutorials & articles
Typical errors of porting C++ code on the 64-bit platform
- Introduction
- Off-warnings
- Use of the functions with a variable number of arguments
- Magic numbers
- Bit shifting operations
- Storing of pointer addresses
- Memsize types in unions
- Change of an array type
- Virtual functions with arguments of memsize type
- Serialization and data exchange
- Pointer address arithmetic
- Arrays indexing
- Mixed use of simple integer types and memsize types
- Implicit type conversions while using functions
- Overload functions
- Data alignment
- The use of outdated functions and predefined constants
- Explicit type conversions
- Error diagnosis
- Unit test
- Code review
- Built-in means of compilers
- Static analyzers
- Conclusion
- Resources
Virtual functions with arguments of memsize type
If there are big derived class graphs with virtual functions in your program, there is a risk to use inattentively arguments of different types but these types actually coincide on the 32-bit system. For example, in the base class you use size_t type as an argument of a virtual function and in the derived class type unsigned. So this code will be incorrect on the 64-bit system.
But an error like this doesn’t necessarily hide in big derived class graphs and here it is one of the examples.
class CWinApp { ... virtual void WinHelp(DWORD_PTR dwData, UINT nCmd); }; class CSampleApp : public CWinApp { ... virtual void WinHelp(DWORD dwData, UINT nCmd); }; |
Let’s follow the life-cycle of the development of some applications. Imagine that firstly it was being developed for Microsoft Visual C++ 6.0 when WinHelp function in CWinApp class had the following prototype:
virtual void WinHelp(DWORD dwData, UINT nCmd = HELP_CONTEXT); |
It was absolutely correct to carry out an overlap of the virtual function in CSampleApp class as it is shown in the example. Then the project was ported into Microsoft Visual C++ 2005 where the function prototype in CWinApp class had undergone some changes which consisted in the replacement of DWORD type with DWORD_PTR type. On the 32-bit system the program will work absolutely correctly for here types DWORD and DWORD_PTR coincide. Troubles will appear during the compilation of the given code for the 64-bit platform. We’ll gave two functions with the same name but different parameters and as a result the user’s code won’t be executed.
The correction consists in the use of the same types in the corresponding virtual functions.
class CSampleApp : public CWinApp { ... virtual void WinHelp(DWORD_PTR dwData, UINT nCmd); }; |
Related articles
Related discussion
-
Microsoft MVP Donald Belcham to Speak on Visual Studio, C# vNext, Aspect Oriented Programming, Live Mesh
by Shaggy123 (0 replies)
-
Using Microsoft Visual Studio to creat a C# Project that nests DLL source as well.
by Complete (0 replies)
-
Adobe Flex reaches out to .NET developers
by ranganathanmca (1 replies)
-
how to write code in VB 5 for printronix printer
by yan_azna (0 replies)
-
conting repeated words
by Slicksim (2 replies)
Related podcasts
-
Looking into the C# Crystal Ball with Charlie Calvert and Bill Wagner
One of the most exciting announcements from PDC was the news about C# 4.0 and Visual Studio 2010. With all the excitement and discussion throughout the event about these new developer tools, we reached out to two experts in the fields. Charlie Calvert and Bill Wagner sat down with Keith and Woody...
Events coming up
-
Dec
6
Developing AJAX Web Applications with Castle Monorail
London, United Kingdom
Monorail is the model-view-controller engine of the Castle Project, bringing many of the best ideas of Ruby on Rails to the .NET world. In this talk, David De Florinier and Gojko Adzic show how Monorail makes it easy to develop .NET based AJAX applications, and how to use the Castle Project to build Web 2.0 applications effectively. Come to this session if you are a .NET web developer. Everyone is welcome!
This thread is for discussions of Typical errors of porting C++ code on the 64-bit platform.