[C++-sig] Re: Can't convert to unsigned int

David Abrahams dave at boost-consulting.com
Thu Dec 12 01:03:12 CET 2002


Nicodemus <nicodemus at globalite.com.br> writes:

> David Abrahams wrote:
>
>>The real question is, how do we represent an unsigned integer
>>constant which requires exactly 32-bits?  We have 3 choices:
>>
>>    1. We don't (current approach, probably not acceptable)
>>
>>    2. PyInt_FromLong(x)
>>
>>    3. A Python Long representing the actual value. It's not so easy
>>    to write down the correct expression for this one ;-)
>>
>
> You said that 2) couldn't represent a unsigned long correctly, because
> it takes as an argument a signed long (or am I missing
> something?)...

Right. It would do whatever the platform does when converting an
unsigned long to a signed long (which is usually to keep the same bit
representation).

> I don't see another way to solve this issue, but to implement unsigned
> longs as PyLongs.
>
> Dave, you said that you wasn't sure about the best approach to this
> problem... what would be the disadvantages of a PyLong approach?

AFAIK, some extension modules (e.g. the Python Win32 API) expect to
receive Python Int objects where 32-bit integer constants are passed
to them, and will raise an exception if passed a Python Long object.

-- 
                       David Abrahams
   dave at boost-consulting.com * http://www.boost-consulting.com
Boost support, enhancements, training, and commercial distribution





More information about the Cplusplus-sig mailing list