I though I would share the portability issues I run into and fixed the last few days:
- Do not use STL API that requires special handling of 64 bits integers. Those can lead to interesting errors (MSVC 6 is a typical example):
My understanding is that the initial STL standard did not acknoledge the existence of 64 bits integers and STL implementor did not extend the API on their own...
- std::ostream do not support 64 bits integer, leading to ambiguous overload compilation error
- std::numeric_limits<> compiles but returns 0 at run_time
- Do not rely on formatting of floating point numbers as string:
MSVC typically always output 3 digits in the exponent, Unix platforms have a varying number of digits
(This was solved by introducing the normalizeFloatingPointStr() function to normalize the formatting of the floating-point exponent)
- uint64 to double conversion is trouble:
Unfortunately no generic recipes. Requires multi-platform testing when introducing new use cases...
- not supported by MSVC6 (worked-around by using int64 to double conversion)
- can run into interesting precision issues when comparing double stored in local variable and FPU registers (that may be of greater precision)
- some strange issue when converting uint64 max to double on the very old XLC 7 compiler (produced -1...)
- Do not use LL and ULL for 64 bits literal
Unfortunately not supported by all compilers (MSVC 6 for instance).
- work-around this by converting an integer to int64. Example: UInt64(1) << 63