]> git.saurik.com Git - wxWidgets.git/commitdiff
Fix wxULongLongNative::ToDouble() compilation with VC6.
authorVadim Zeitlin <vadim@wxwidgets.org>
Thu, 28 Apr 2011 16:16:16 +0000 (16:16 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Thu, 28 Apr 2011 16:16:16 +0000 (16:16 +0000)
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
src/common/longlong.cpp

index cd6b752d1e2d9b96eaeed0918381ff86b42a88aa..f248bb6d21ac7721ccf00f18e03515052b87f172 100644 (file)
@@ -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
index 27e771096da29796855d956a49d19cc88c1449c8..1ceefe012303c0677d29e8b557b4face30673d26 100644 (file)
@@ -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
 
 // ============================================================================