[CoinUtils-tickets] [COIN-OR Common Utilities] #86: CoinMessageHandler fails under 64-bit Microsoft C++
COIN-OR Common Utilities
coin-trac at coin-or.org
Fri Dec 12 19:05:01 EST 2014
#86: CoinMessageHandler fails under 64-bit Microsoft C++
-------------------+---------------
Reporter: wxBen | Owner:
Type: defect | Status: new
Priority: major | Version:
Keywords: |
-------------------+---------------
In CoinMessageHandler.cpp, there are **three** instance of code that uses
"long offset" as in:
{{{
long int offset = temp - (char *) rhs.message_;
}}}
Visual C++ 64-bit treats "long int" as four bytes, but pointers are eight
bytes of course. Stupid, I know. But it makes it crash. So my quick fox
for this is as follows:
{{{
#ifdef _WIN64
__int64 offset = temp - (char *) rhs.message_;
#else
long int offset = temp - (char *) rhs.message_;
#endif
}}}
So my request is, please fix the three instances in this file to be more
portable. Perhaps rather than test for _WIN64 which may be MS specific,
you can use size_t (which is eight bytes under 64-bit VSS). Or rewrite
that code to not do pointer arithmetic using longs.
This is sadly a problem that plagues a lot of software, so sqlite for
example, has a header file that tests and defines types accordingly, for
example:
{{{
#if defined(_MSC_VER) || defined(__BORLANDC__)
typedef __int64 sqlite_int64;
typedef unsigned __int64 sqlite_uint64;
#else
typedef long long int sqlite_int64;
typedef unsigned long long int sqlite_uint64;
#endif
typedef sqlite_int64 sqlite3_int64;
typedef sqlite_uint64 sqlite3_uint64;
}}}
--
Ticket URL: <https://projects.coin-or.org/CoinUtils/ticket/86>
COIN-OR Common Utilities <http://projects.coin-or.org/CoinUtils>
Common data structures and linear algebra functions for COIN-OR projects
More information about the CoinUtils-tickets
mailing list