1

Is there a way that I can move a pointer to be n bytes later in Cython?

For instance, if I have (pseudo code):

cdef void *n_ary 
cdef void *eightbytes 
cdef void *n_ary_plus8

ary = cnp.PyArray_DATA(input_array)
eightbytes = 8
n_ary_plus8 = ary + eightbytes

I get the error Invalid operand types for '+' (void *; void *) for the last line telling me that it does not know how to add the pointer address ary and the pointer eightbytes. It seems like this ought to be obvious but I can't find anything in the manual or this august reference.

2 Answers2

2

void* arithmetic is not allowed by the C and C++ standards. If you want to do it, you need to convert the pointer to a char* type.

For more information, please look at this and this. Be very careful of the strict aliasing rule with such pointer casts (padding and alignment too).

Jérôme Richard
  • 41,678
  • 6
  • 29
  • 59
0

I was able to do what I needed to do with

cdef void *n_ary 
cdef int eightbytes 
cdef void *n_ary_plus8

ary = cnp.PyArray_DATA(input_array)
eightbytes = 8
n_ary_plus8 = &ary[eightbytes]