views:

92

answers:

1

I want to define initialized C-array in Pyrex, e.g. equivalent of:

unsigned char a[8] = {0,1,2,3,4,5,6,7};

What will be equivalent in Pyrex?

Just array is

cdef unsigned char a[8]

But how can I made it initialized with my values?

+1  A: 

In Cython, Pyrex's successor, this feature was added over a year a go to fix this feature request, so for example the following works in Cython now:

cdef double a[] = [0.5, 0.3, 0.1, 0.1]

However, Pyrex's development is proceeding much more slowly (which is why Cython was forked years ago by developers rarin' for faster action), so I doubt it's picked up this feature (though you can try, esp. if you're using the very latest release of Pyrex, 0.9.8.6).

If Pyrex isn't giving you the features you want, may I suggest switching to Cython instead? Most Pyrex code should just recompile smoothly in Cython, and you do get the extra features this way.

Alex Martelli
Thanks Alex, but I can't use Cython because it supports only gcc, at least when I've checked it last time. I need compatibility with MSVC too.
bialix
@bialix, recent fixes should allow Cython to work around msvc's limitations, though not all made it into 0.12.1 -- if you use mercurial to get http://hg.cython.org/cython-devel/ you could check if it works w/the specific release of msvc (and otherwise open a bug). BTW, it does work fine w/mingw32, which is link-compatible with msvc and therefore standard CPython windows versions.
Alex Martelli