How to get rid of "hex/oct constants > sys.maxint" warning?

Michael Hudson mwh at python.net
Wed Aug 11 11:39:51 EDT 2004


Grant Edwards <grante at visi.com> writes:

> I'm getting tired of seeing meaningless warnings from my code,
> but I can't figure out how to get rid of them:
> 
> For example:
> 
> fcntl.ioctl(fd,0xc0047a80,s)   causes
> 
>   FutureWarning: hex/oct constants > sys.maxint will return
>   positive values in Python 2.4 and up
> 
> Firstly, I have no idea what that error means in this context.
> 0xc0047a80 isn't intended to be an integer (either positive or
> negative): it's just a chunk of 32 bits.
>   
> Googling the newsgroup came up with the suggestion that putting
> an "L" on the end of the constant would eliminate the warning,
> but it causes an error:
> 
> fcntl.ioctl(fd,0xc0047a80L,s)  causes
> 
>   OverflowError: long int too large to convert to int
> 
> So, that doesn't work.
> 
> How _do_ I get rid of the warning?  Is there a way to tell
> Python that the constant isn't an integer, it's just a bit
> pattern?

It's horrible, but ~int(~0xc0047a80L&0xFFFFFFFFL) will work.

Cheers,
mwh

-- 
  I love the way Microsoft follows standards.  In much the same
  manner that fish follow migrating caribou.           -- Paul Tomblin
               -- http://home.xnet.com/~raven/Sysadmin/ASR.Quotes.html



More information about the Python-list mailing list