[Pyrex] error: conversion to non-scalar type requested

Sven Berkvens-Matthijsse sven at pyrex.berkvens.net
Thu Apr 10 22:43:52 CEST 2008


> Now I've not the code to try this, but I think it doesn't solve the
> problem.  func function needs a struct in_addr, not a pointer to
> struct in_addr, so the cast is correct. Maybe the problem is in the
> generated C code. I'll post the original pyrex (and C generated)
> code that originate this error very soon to give you more details.

No, what Lenard said is correct, the cast binds stronger than the []
operator. What you said:

	tmp = <in_addr>tmpinPtr[0]

actually reads as:

	tmp = (<in_addr>tmpinPtr)[0]

which of course does not work. What Lenard says reads as:

	tmp = (<in_addr *>tmpinPtr)[0]

which is correct. Of course, you can write it your way, just be sure
to use parentheses in that case, like this:

	tmp = <in_addr>(tmpinPtr[0])

-- 
Sven



> 2008/4/10, Lenard Lindstrom <len-l at telus.net>:
> >
> > The problems is with <in_addr>. It casts tmpinPtr to an in_addr
> > structure, not a pointer to in_addr (in_addr *). Try this:
> >
> >
> > tmp = <in_addr *>tmpinPtr[0]
> >
> >
> >
> > Lenard
> >
> >
> >
> > Daniele Pianu wrote:
> > > Suppose this code
> > >
> > > # getIstance return a long, that is a pointer to a in_addr struct
> > > cdef in_addr tmp
> > > tmpinPtr = in_.getIstance()
> > > tmp = <in_addr>tmpinPtr[0]
> > >
> > > # in this function gcc gives me an error
> > > func( tmp )
> > >
> > > I take a pointer to a in_addr struct as a python long from the
> > > getIstance method. Then, I need to call a C function and pass a
> > > in_addr struct by value. With pyrex C the pyrex code compiles with no
> > > problems. But gcc gives me the error in mail's subject.
> > >
> > > error: conversion to non-scalar type requested
> > >
> > > How can I pass the structure by value deferencing a python long and
> > > casting it as the struct type I need?
> > >
> > > (I've wrote similiar code for function where I pass the structure by
> > > reference and there's no problems.)



More information about the Pyrex mailing list