cannot dereference pointer

1,081 views
Skip to first unread message

Jeff

unread,
Aug 20, 2010, 4:25:57 PM8/20/10
to cython-users
Using cython 0.13 beta.
Okay, I'm trying to convert a python object and return the equivalent
C type. I have one of each C type declared on the stack in the
calling code and passed by pointer to the conversion function. I hope
it's clear what I'm trying to do, even if it isn't elegant. I'm
getting errors such as the following, one for each pointer I'm trying
to dereference:

Cannot assign type 'int' to 'int *'

So the dereference isn't understood? I want the python-to-C type
conversion to occur and assign to the appropriate dereferenced C
value.

cdef void* convert_multiplier(int gtype, value,
int *iv, long *lv, long long *llv, float *fv, double *dv):
if gtype == C_INT:
if value:
*iv = value
return iv
elif gtype == C_LONG:
if value:
*lv = value
return lv
elif gtype == C_LONGLONG:
if value:
*llv = value
return llv
elif gtype == C_FLT:
if value:
*fv = value
return fv
elif gtype == C_DBL:
if value:
*dv = value
return dv
else:
raise TypeError, "type of g_a not recognized"

Stefan Behnel

unread,
Aug 20, 2010, 4:42:06 PM8/20/10
to cython...@googlegroups.com
Jeff, 20.08.2010 22:25:

> Using cython 0.13 beta.
> Okay, I'm trying to convert a python object and return the equivalent
> C type. I have one of each C type declared on the stack in the
> calling code and passed by pointer to the conversion function. I hope
> it's clear what I'm trying to do, even if it isn't elegant. I'm
> getting errors such as the following, one for each pointer I'm trying
> to dereference:
>
> Cannot assign type 'int' to 'int *'
>
> So the dereference isn't understood? I want the python-to-C type
> conversion to occur and assign to the appropriate dereferenced C
> value.
>
> cdef void* convert_multiplier(int gtype, value,
> int *iv, long *lv, long long *llv, float *fv, double *dv):
> if gtype == C_INT:
> if value:
> *iv = value

Use

iv[0] = value

http://docs.cython.org/src/userguide/language_basics.html#differences-between-c-and-cython-expressions

The unary '*' operator has a different meaning in Python.

Stefan

Reply all
Reply to author
Forward
0 new messages