From 30e9f7bacd6de73eeb463cc888b337c40eac6098 Mon Sep 17 00:00:00 2001 From: Richard Kreckel Date: Sat, 9 Apr 2011 10:04:39 +0200 Subject: [PATCH] Support for MSVC. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch works around problems MSVC has with extern "C" declarations inside namespace cln. As a result, it should work with MS 32-bit compiler version 16.00.30319.01. Thanks to Jan Rheinländer . --- examples/e.cc | 4 ++-- include/cln/number.h | 12 ++++++++++++ src/base/cl_low.h | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/examples/e.cc b/examples/e.cc index 9aa7c63..53afa55 100644 --- a/examples/e.cc +++ b/examples/e.cc @@ -72,13 +72,13 @@ sum_exp1 (uintC a, uintC b, cl_I & first, cl_I & second) } namespace cln { - extern cl_LF cl_I_to_LF(const cl_I&, uintC); + extern const cl_LF cl_I_to_LF(const cl_I&, uintC); } void const_exp1 (cl_LF & result, uintC dec) { - uintC c = (uintC) (dec * ::log (10)); + uintC c = (uintC) (dec * ::log (10.0)); uintC n = dec; uintC actuallen = (uintC)(3.321928094 * dec / intDsize); n = (uintC) ((n + c) / ::log ((double)n)); diff --git a/include/cln/number.h b/include/cln/number.h index f0c0c8a..b5ac95f 100644 --- a/include/cln/number.h +++ b/include/cln/number.h @@ -25,6 +25,18 @@ // Constructors and assignment operators from C numeric types. +#ifdef _MSC_VER +// Workaround to force MSVC to tag the symbol with the cln:: namespace +// When declaring inside an inlined function the symbol is placed in the +// global namespace! +namespace cln { +extern cl_private_thing cl_I_constructor_from_L (sint32 wert); +extern cl_private_thing cl_I_constructor_from_UL (uint32 wert); +extern cl_private_thing cl_I_constructor_from_Q (sint64 wert); +extern cl_private_thing cl_I_constructor_from_UQ (uint64 wert); +} +#endif + #define CL_DEFINE_INT_CONSTRUCTOR(_class_,_type_) \ inline _class_::_class_ (const _type_ wert) \ { \ diff --git a/src/base/cl_low.h b/src/base/cl_low.h index 553f126..c4c25ab 100644 --- a/src/base/cl_low.h +++ b/src/base/cl_low.h @@ -202,7 +202,13 @@ inline uint32 mulu32_unchecked (uint32 arg1, uint32 arg2) // > arg1, arg2 : zwei 32-Bit-Zahlen // < 2^32*hi+lo : eine 64-Bit-Zahl extern "C" uint32 mulu32_ (uint32 arg1, uint32 arg2); // -> Low-Teil +#ifdef _MSC_VER + // Workaround MSVC compiler bug: extern "C" results in wrong symbols, when + // declared inside a namespace! +} extern "C" uint32 mulu32_high; namespace cln { // -> High-Teil +#else extern "C" uint32 mulu32_high; // -> High-Teil +#endif #if defined(__GNUC__) && defined(__m68k__) && !defined(NO_ASM) #define mulu32(x,y,hi_zuweisung,lo_zuweisung) \ ({ var uint32 _x = (x); \ @@ -336,7 +342,12 @@ inline uint32 mulu32_unchecked (uint32 arg1, uint32 arg2) // > arg1, arg2 : zwei 64-Bit-Zahlen // < 2^64*hi+lo : eine 128-Bit-Zahl extern "C" uint64 mulu64_ (uint64 arg1, uint64 arg2); // -> Low-Teil +#ifdef _MSC_VER + // Workaround MSVC compiler bug. +} extern "C" uint64 mulu64_high; namespace cln { // -> High-Teil +#else extern "C" uint64 mulu64_high; // -> High-Teil +#endif #if defined(__GNUC__) && defined(__alpha__) && !defined(NO_ASM) #define mulu64(x,y,hi_zuweisung,lo_zuweisung) \ ({ var register uint64 _x = (x); \ @@ -424,8 +435,13 @@ inline uint32 mulu32_unchecked (uint32 arg1, uint32 arg2) extern "C" uint32 divu_3216_1616_ (uint32 x, uint16 y); // -> Quotient q, Rest r #else extern "C" uint16 divu_3216_1616_ (uint32 x, uint16 y); // -> Quotient q +#ifdef _MSC_VER + // Workaround MSVC compiler bug. +} extern "C" uint16 divu_16_rest; namespace cln { // -> Rest r +#else extern "C" uint16 divu_16_rest; // -> Rest r #endif +#endif #if defined(__GNUC__) && defined(__sparc64__) && !defined(NO_ASM) #define divu_3216_1616(x,y,q_zuweisung,r_zuweisung) \ ({var uint32 __x = (x); \ @@ -514,7 +530,12 @@ inline uint32 mulu32_unchecked (uint32 arg1, uint32 arg2) // < uint16 r: x mod y // < x = q*y+r extern "C" uint32 divu_3216_3216_ (uint32 x, uint16 y); // -> Quotient q +#ifdef _MSC_VER + // Workaround MSVC compiler bug. +} extern "C" uint16 divu_16_rest; namespace cln { // -> Rest r +#else extern "C" uint16 divu_16_rest; // -> Rest r +#endif #if defined(__GNUC__) && defined(__sparc64__) && !defined(NO_ASM) #define divu_3216_3216(x,y,q_zuweisung,r_zuweisung) \ ({var uint32 __x = (x); \ @@ -564,7 +585,12 @@ inline uint32 mulu32_unchecked (uint32 arg1, uint32 arg2) // < uint32 r: x mod y // < x = q*y+r extern "C" uint32 divu_3232_3232_ (uint32 x, uint32 y); // -> Quotient q +#ifdef _MSC_VER + // Workaround MSVC compiler bug. +} extern "C" uint32 divu_32_rest; namespace cln { // -> Rest r +#else extern "C" uint32 divu_32_rest; // -> Rest r +#endif #if defined(__GNUC__) && defined(__sparc64__) && !defined(NO_ASM) #define divu_3232_3232(x,y,q_zuweisung,r_zuweisung) \ ({var uint32 __x = (x); \ @@ -661,7 +687,12 @@ inline uint32 mulu32_unchecked (uint32 arg1, uint32 arg2) // < uint32 r: x mod y // < x = q*y+r extern "C" uint32 divu_6432_3232_ (uint32 xhi, uint32 xlo, uint32 y); // -> Quotient q +#ifdef _MSC_VER + // Workaround MSVC compiler bug. +} extern "C" uint32 divu_32_rest; namespace cln { // -> Rest r +#else extern "C" uint32 divu_32_rest; // -> Rest r +#endif #if defined(__GNUC__) && defined(__m68k__) && !defined(NO_ASM) #define divu_6432_3232(xhi,xlo,y,q_zuweisung,r_zuweisung) \ ({var uint32 __xhi = (xhi); \ @@ -944,7 +975,12 @@ inline uint32 mulu32_unchecked (uint32 arg1, uint32 arg2) // multiplication is slower or faster than our own divu_6464_6464_ routine. // Anyway, call our own routine. extern "C" uint64 divu_6464_6464_ (uint64 x, uint64 y); // -> Quotient q +#ifdef _MSC_VER + // Workaround MSVC compiler bug. +} extern "C" uint64 divu_64_rest; namespace cln { // -> Rest r +#else extern "C" uint64 divu_64_rest; // -> Rest r +#endif #define divu_6464_6464(x,y,q_zuweisung,r_zuweisung) \ { q_zuweisung divu_6464_6464_(x,y); r_zuweisung divu_64_rest; } #define NEED_VAR_divu_64_rest @@ -961,7 +997,12 @@ inline uint32 mulu32_unchecked (uint32 arg1, uint32 arg2) // < uint64 r: x mod y // < x = q*y+r extern "C" uint64 divu_12864_6464_ (uint64 xhi, uint64 xlo, uint64 y); // -> Quotient q +#ifdef _MSC_VER + // Workaround MSVC compiler bug. +} extern "C" uint64 divu_64_rest; namespace cln { // -> Rest r +#else extern "C" uint64 divu_64_rest; // -> Rest r +#endif #if defined(__GNUC__) && defined(__x86_64__) && !defined(NO_ASM) #define divu_12864_6464(xhi,xlo,y,q_zuweisung,r_zuweisung) \ ({var uint64 __xhi = (xhi); \