From 4c24ca50d6d41f93d5c21e568e759f6382d61c09 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 28 Apr 2011 16:16:16 +0000 Subject: [PATCH] Fix wxULongLongNative::ToDouble() compilation with VC6. The problem alluded to by the commit message of r40658 arose only in the DLL build using VC6 so reintroduce the workaround for it removed by r67634 but make it VC6-specific and, arguably even more importantly, also make it work correctly for wxULongLongNative values greater than LONGLONG_MAX. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@67643 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/longlong.h | 9 +++++++++ src/common/longlong.cpp | 16 ++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/include/wx/longlong.h b/include/wx/longlong.h index cd6b752d1e..f248bb6d21 100644 --- a/include/wx/longlong.h +++ b/include/wx/longlong.h @@ -411,7 +411,16 @@ public: } // convert to double + // + // For some completely obscure reasons compiling the cast below with + // VC6 in DLL builds only (!) results in "error C2520: conversion from + // unsigned __int64 to double not implemented, use signed __int64" so + // we must use a different version for that compiler. +#ifdef __VISUALC6__ + double ToDouble() const; +#else double ToDouble() const { return wx_truncate_cast(double, m_ll); } +#endif // operations // addition diff --git a/src/common/longlong.cpp b/src/common/longlong.cpp index 27e771096d..1ceefe0123 100644 --- a/src/common/longlong.cpp +++ b/src/common/longlong.cpp @@ -133,6 +133,22 @@ wxULongLongNative& wxULongLongNative::operator=(const class wxULongLongWx &ll) } #endif +#ifdef __VISUALC6__ +double wxULongLongNative::ToDouble() const +{ + // Work around the problem of casting unsigned __int64 to double in VC6 + // (which for unknown reasons only manifests itself in DLL builds, i.e. + // when using /MD). + static const __int64 int64_t_max = 9223372036854775807i64; + if ( m_ll <= int64_t_max ) + return wx_truncate_cast(double, (wxLongLong_t)m_ll); + + double d = wx_truncate_cast(double, int64_t_max); + d += (__int64)(m_ll - int64_t_max - 1); // The cast is safe because of -1 + return d + 1; +} +#endif // __VISUALC6__ + #endif // wxUSE_LONGLONG_NATIVE // ============================================================================ -- 2.47.2