[C++-sig] Re: Re: long long unsigned issue...

Milind Patil milind_patil at hotmail.com
Sun May 4 03:29:55 CEST 2003


"David Abrahams" <dave at boost-consulting.com> wrote in message
news:u65oriktt.fsf at boost-consulting.com...
> "Milind Patil" <milind_patil at hotmail.com> writes:
>
> >> > I am seeking a behaviour where python int is converted to c++ int
> >> > before constructing to c++ object Y, and python long is converted
> >> > to c++ long long unsigned int before constructing to c++ object Y.
> >>
> >> Do you really need to handle the cases differently?
> >>
> >
> > Not explicitly. But consider if I want to do
> >
> > z = hello.Y(~0)
> > or
> > z = hello.Y(-1)
> >
> > This is best converted to Y(int) constructor.
>
> Why?

Because if I have constructor Y(long unsigned unsigned int) precede
Y(int) (and you rightly said it masks the int), then I get

OverflowError: bad numeric cast: loss of range in numeric_cast

for the python statement z = hello.Y(-1).  There is no way to convert a
python -1L to a c++ long long unsigned int.

> > I read up a bit on python long and learned that it is not like the
> > c++ long. It seems the python long is a structure and is not width
> > bound. How does boost handle python boost to long conversion?
>
> What is "python boost to long conversion"?  Please be specific.

I meant python long to c++ long conversion by boost. For example,
what happens if the python long is more than 64 bits wide? How do I
handle this in c++?

Thanks,
Milind







More information about the Cplusplus-sig mailing list