• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Lesson 22. Pattern 14. Overloaded functions
 

Lesson 22. Pattern 14. Overloaded functions

on

  • 235 views

When porting a 32-bit program to a 64-bit platform, you may encounter changes in its logic related to the use of overloaded functions. If a function is overlapped for 32-bit and 64-bit values, the ...

When porting a 32-bit program to a 64-bit platform, you may encounter changes in its logic related to the use of overloaded functions. If a function is overlapped for 32-bit and 64-bit values, the access to it with an argument of a memsize-type will be translated into different calls on different systems.

Statistics

Views

Total Views
235
Views on SlideShare
235
Embed Views
0

Actions

Likes
0
Downloads
0
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Lesson 22. Pattern 14. Overloaded functions Lesson 22. Pattern 14. Overloaded functions Document Transcript

    • Lesson 22. Pattern 14. OverloadedfunctionsWhen porting a 32-bit program to a 64-bit platform, you may encounter changes in its logic related tothe use of overloaded functions. If a function is overlapped for 32-bit and 64-bit values, the access to itwith an argument of a memsize-type will be translated into different calls on different systems. Thistechnique may be useful as, for example, in this code:static size_t GetBitCount(const unsigned __int32 &) { return 32;}static size_t GetBitCount(const unsigned __int64 &) { return 64;}size_t a;size_t bitCount = GetBitCount(a);But this change of logic is potentially dangerous. Imagine a program that uses a class to arrange thestack. This class is specific in that way that it allows you to store values of different types:class MyStack {...public: void Push(__int32 &); void Push(__int64 &); void Pop(__int32 &); void Pop(__int64 &);} stack;ptrdiff_t value_1;stack.Push(value_1);...int value_2;stack.Pop(value_2);
    • A careless programmer saves into and then selects from the stack values of different types ("ptrdiff_t"and "int"). Their sizes coincide on the 32-bit system and everything is quite okay. But when the size ofthe type "ptrdiff_t" changes on the 64-bit system, the number of bytes saved into the stack gets largerthan the number of bytes loaded then from the stack.I think this type of errors is clear to you and you understand that one should be very careful about callsto overloaded functions when passing actual arguments of a memsize-type.DiagnosisPVS-Studio does not diagnose this pattern of 64-bit errors. First, it is explained by the fact that we havenot encountered such an error in a real application yet, and second, diagnosis of such constructsinvolves some difficulties. Please write to us if you encounter such an error in real code.The course authors: Andrey Karpov (karpov@viva64.com), Evgeniy Ryzhkov (evg@viva64.com).The rightholder of the course "Lessons on development of 64-bit C/C++ applications" is OOO "ProgramVerification Systems". The company develops software in the sphere of source program code analysis.The companys site: http://www.viva64.com.Contacts: e-mail: support@viva64.com, Tula, 300027, PO box 1800.