[or-cvs] MSVC6 is apparently terrified of unnatural cross-breeding b...
Nick Mathewson
nickm at seul.org
Mon Jul 17 00:39:07 UTC 2006
Update of /home/or/cvsroot/tor/src/common
In directory moria:/tmp/cvs-serv12195/src/common
Modified Files:
compat.h
Log Message:
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.
Index: compat.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/common/compat.h,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -p -d -r1.49 -r1.50
--- compat.h 4 Jul 2006 03:25:07 -0000 1.49
+++ compat.h 17 Jul 2006 00:39:05 -0000 1.50
@@ -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. */
More information about the tor-commits
mailing list