summaryrefslogtreecommitdiff
path: root/src/common/compat.h
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2006-07-17 00:39:05 +0000
committerNick Mathewson <nickm@torproject.org>2006-07-17 00:39:05 +0000
commite572d5990c4ed5100338a4e1ad4cae6a55329b4f (patch)
tree18ec12edf7054392a0203a327a5b4bd11f9026b2 /src/common/compat.h
parent169d6c4aca43ea574762f42542a9db4745396ff8 (diff)
downloadtor-e572d5990c4ed5100338a4e1ad4cae6a55329b4f.tar.gz
tor-e572d5990c4ed5100338a4e1ad4cae6a55329b4f.zip
MSVC6 is apparently terrified of unnatural cross-breeding between uint64_t and double, and needs more persuasion than usual to cast one to the other. Issue identified by Frediano Ziglio; patch revised for minimal impact on non-MSVC6 compilers.
svn:r6768
Diffstat (limited to 'src/common/compat.h')
-rw-r--r--src/common/compat.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/common/compat.h b/src/common/compat.h
index abacce231a..fde91172d4 100644
--- a/src/common/compat.h
+++ b/src/common/compat.h
@@ -76,6 +76,19 @@
#endif /* ifndef MAVE_MACRO__func__ */
#endif /* if not windows */
+#if defined(_MSC_VER) && (_MSC_VER < 1300)
+/* MSVC versions before 7 apparently don't believe that you can cast uint64_t
+ * to double and really mean it. */
+extern inline double U64_TO_DBL(uint64_t x) {
+ int64_t i = (int64_t) x;
+ return (i < 0) ? ((double) INT64_MAX) : (double) i;
+}
+#define DBL_TO_U64(x) ((uint64_t)(int64_t) (x))
+#else
+#define U64_TO_DBL(x) ((double) (x))
+#define DBL_TO_U64(x) ((uint64_t) (x))
+#endif
+
/* ===== String compatibility */
#ifdef MS_WINDOWS
/* Windows names string functions differently from most other platforms. */