Boost logo

Boost :

From: Jonathan Wakely (cow_at_[hidden])
Date: 2004-09-01 08:44:43


On Wed, Sep 01, 2004 at 12:50:32PM +0200, Markus Sch?pflin wrote:

> Currently the integer tests report an error on 64 bit platforms, as can be
> seen on http://tinyurl.com/6whtg
>
> The following code in integer_test.cpp causes the problem:
>
> PRIVATE_FIT_TESTS( int_t, least, long, LONG_MAX );
> PRIVATE_FIT_TESTS( int_t, fast, long, LONG_MAX );
> PRIVATE_FIT_TESTS( uint_t, least, unsigned long, ULONG_MAX );
> PRIVATE_FIT_TESTS( uint_t, fast, unsigned long, ULONG_MAX );
>
> The first line expands to:
>
> do {
> long v = LONG_MAX ;
> PRIVATE_FIT_TEST(int_t, 32, least, v);
> v >>= 1;
> PRIVATE_FIT_TEST(int_t, 31, least, v);
> v >>= 1;
> ...
> }
>
> which becomes:
>
> do {
> long v = LONG_MAX ;
> BOOST_TEST( int_t < 32 > :: least ( v ) == v );
> v >>= 1;
> BOOST_TEST( int_t < 31 > :: least ( v ) == v );
> v >>= 1;
> ...
> }
>
> which of course alway fails on 64 bit platforms because LONG_MAX is a 64
> bit number.
>
> A possible fix would be to start the test with 64 bit and not 32 on 64 bit
> platforms. But how can 64 bit platforms be detected? Probably with #if
> (LONG_MAX > INT_MAX) ... #endif or something like this.

This is not _guaranteed_ to work, but would be OK in practice.

An ILP64 platform would have sizeof(int) == sizeof(long) == 8
and an LLP64 platform would have sizeof(int) == sizeof(long) == 4

In both cases LONG_MAX == INT_MAX.

I think all 64-bit unices use the LP64 model, where sizeof(int) == 4 and
sizeof(long) == 8, so I think your suggestion would work.

> Another fix (which ignores 64 bit values alltogether) would be to change
> the lines above to not use long and LONG_MAX but int and INT_MAX.

As I understand it that just changes the bad assumption that long is
32-bits to assuming that int is 32 (or fewer) bits, which is still an
unportable assumption, but likely to work for the foreseeable future
(famous last words :-)

jon

-- 
I don't pretend to be an expert on intellectual property law, but I do
know one thing. If a music industry executive claims I should agree with
their agenda because it will make me more money, I put my hand on my wallet
... and check it after they leave, just to make sure nothing's missing.
	- Janis Ian <http://www.janisian.com/article-internet_debacle.html>

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk