FutureWarning question
A. Lloyd Flanagan
alloydflanagan at comcast.net
Tue Apr 13 11:46:41 EDT 2004
Mike <mike at nospam.com> wrote in message news:<16mnetilcmds6.1apnyu46tbjpw.dlg at 40tude.net>...
> I ran across the message below in 2.3.2 today. These are the lines of code:
>
> 402: if m1_hi >> 15 & 0x0001 == 1:
> 403: m1_hi = m1_hi | 0xFFFF0000
> 404: if m1_lo >> 15 & 0x0001 == 1:
> 405: m1_lo = m1_lo | 0xFFFF0000
>
> This is the warning message:
>
> pwg.py:403: FutureWarning: hex/oct constants > sys.maxint will return
> positive values in Python 2.4 and up
> m1_hi = m1_hi | 0xFFFF0000
sys.maxint is the largest number that will fit into an int data type.
Although your constant is 32 bits, the high bit is set, so it gets
interpreted as a negative number.
>>> x = 0xFFFF0000
>>> x
-65536
In future versions of python, constants which are larger than
sys.maxint will not be interpreted as negative, but will automatically
be promoted to a long integer. The distinction between the two
integer types will pretty much disappear.
So, your constant will evaluate to a positive long integer
(4294901760L). Since you're using it as a bit mask, and not a number,
I don't think it will make a difference for your application. But the
compiler can't tell for sure, so it warns you anyway.
More information about the Python-list
mailing list