16

I'd like to do exactly this in Cython:

cdef int shiftIndexes[] = [1,-1, 0, 2,-1, -1, 4, 0, -1, 8, 1, -1, 16, 1, 0, 32, 1, 1, 64, 0, 1, 128, -1, 1]

I've seen a few references in fixed bug reports and old email lists that static array functionality exists in Cython, but I can't find anty examples and this particular example gives me a syntax error: Syntax error in C variable declaration

Is it possible to make static C arrays with Cython?

Rich
  • 12,068
  • 9
  • 62
  • 94

1 Answers1

28

Use pointer notation instead:

cdef int *shiftIndexes = [1,-1, 0, 2,-1, -1, 4, 0, -1, 8, 1, -1, 16, 1, 0, 32, 1, 1, 64, 0, 1, 128, -1, 1]

And it will work like a charm.

tito
  • 12,990
  • 1
  • 55
  • 75