FutureWarning/OverFlow error and 0xffff0000
Mark Hammond
mhammond at skippinet.com.au
Thu Feb 20 22:41:26 EST 2003
Richard Jones wrote:
> My code has a couple of instances of 0xffff0000 in it - they're bitmask flags
> to windows calls. Up until 2.3, all was well. Now in 2.3, I get warnings
> "FutureWarning: hex/oct constants > sys.maxint will return positive values in
> Python 2.4 and up" about that value. The first solution I came up with was to
> suppress the warning before I import the specific module that has the
> literal.
>
> I fleetingly noticed someone suggest that I use a long int literal instead:
> 0xffff0000L
>
> No dice. On older versions of Python, this generates an "OverflowError: long
> int too large to convert to int".
>
As the value is a bitmask, you may not want a long - the value is going
to end up in a C 'int'.
I believe the 'correct' solution is to use a decimal literal - -65536 in
this case.
It is unclear what Python 2.4 will do about these constants. This has
come up on python-dev before, but been punted. The win32 extensions in
particular would be burdended by this, as we use *lots* of hex
constants, typically generated by h2py.py.
Keep you eye on the python-dev summaries post the 2.3 release - it will
come up again.
Mark.
More information about the Python-list
mailing list