LONG_BIT == 64, can't compile

jay.krell at cornell.edu jay.krell at cornell.edu
Sun Oct 15 07:27:12 EDT 2000


Shouldn't 2147483647 == 2147483647L?
For most purposes
    #define LONG_BIT (CHAR_BIT * sizeof(long))
works
(for that matter #define bitsof(x) (CHAR_BIT * sizeof(x)) )

but not if you later do like
#if LONG_BIT==64
...
#endif

Another possible definition is
#if LONG_MAX > 2147483647
#define LONG_BIT 64
#else
#define LONG_BIT 32
#endif

I tried this with Visual C+++ 5.0 and Cygwin and FreeBSD 4.1 gcc 2.95.2
19991024 (release-2) and it printed 1 with all three.
#include <stdio.h>
int main()
{
 int i = (2147483647 == 2147483647L);
 printf("%d\n", i);
 return 0;
}

The type of "2147483647" can vary between machines. It is int on most, if
int is 32 bits, otherwise long, but its value I think should always be
2147483647, even when compared to 2147483647L which is always of type long.
That is, there should be unsigned or negative problem. The only way I can
imagine it getting messed up is if you do like (long)(short)2147483647 or
(int)(short)2147483647 (on 32bit machines), in which case you are likely to
end up with -1. Yes, I tried that with the compilers too and got -1.

I guess I need to get GCC 2.95.2 20000220..

 - Jay


>    # define LONG_BIT 32
>    #else
>    /* Safe assumption.  */
>    # define LONG_BIT 64
>    #endif
>
>This fails, becauls LONG_MAX is defined to 2147483647L

-----Original Message-----
From: Johannes Zellner <johannes at zellner.org>
Newsgroups: comp.lang.python
To: python-list at python.org <python-list at python.org>
Date: Sunday, October 15, 2000 2:51 AM
Subject: Re: LONG_BIT == 64, can't compile


>In article <slrn8uiiif.bo4.johannes at kristine.zellner.org>, Johannes Zellner
wrote:
>>Hello,
>>
>>the following lines of the latest python from cvs
>>make it uncompilable here:
>>
>>Include/pyport.h:384
>>
>>#if LONG_BIT != 8 * SIZEOF_LONG
>>/* 04-Oct-2000 LONG_BIT is apparently (mis)defined as 64 on some recent
>> * 32-bit platforms using gcc.  We try to catch that here at compile-time
>> * rather than waiting for integer multiplication to trigger bogus
>> * overflows.
>> */
>>#error "LONG_BIT definition appears wrong for platform (bad gcc config?)."
>>#endif
>>
>>
>>LONG_BIT is apparently 64 here.
>>
>>I use:
>>
>>    GCC 2.95.2 20000220 (Debian GNU/Linux)
>>
>>hmm. I just commented out the above lines which makes python
>>compile but I can't do integer multiplictaions.
>>
>>So: how can I compile the stuff then ?
>
>I located the problem to be in /usr/include/bits/xopen_lim.h:
>
>    /* Number of bits in a word of type `long int'.  */
>    #if LONG_MAX == 2147483647
>    # define LONG_BIT 32
>    #else
>    /* Safe assumption.  */
>    # define LONG_BIT 64
>    #endif
>
>This fails, becauls LONG_MAX is defined to 2147483647L
>                                                     ^
>
>Where does this have to be reported ?
>
>
>So again: how can I compile the stuff to get proper integer operations ?
>can I simply override the definition of LONG_BIT to 32 ?
>
>--
>   Johannes
>--
>http://www.python.org/mailman/listinfo/python-list





More information about the Python-list mailing list