[Pyrex] Arrays in structures

Sven Berkvens-Matthijsse sven at pyrex.berkvens.net
Sun May 27 12:01:17 UTC 2007


> Hello,

Hello,

> Is there any way to define a normal array in a c structure binding?
> 
> cdef extern from "limits.h"
>   cdef int PATH_MAX
> 
> cdef extern from "test.h"
>   cdef struct __test
>     char name[PATH_MAX]

It seems to work fine if you write this:

cdef extern from "limits.h":
  enum:
    PATH_MAX

cdef extern from "test.h":
  struct __test:
    char name[PATH_MAX]

> The problems here: I don't know if PATH_MAX is imported properly. It
> seems to be some #define out of the limits.h.

It is indeed. Using the "enum" construction makes Pyrex use is as-is.

> Also, the error i get is in char name[PATH_MAX]: Not allowed in a
> constant expression.

That's because you were defining it as a variable. Using "enum" makes
it a constant. Pyrex doesn't know it's value, but doesn't need to
because the C compiler fills it in where necessary.

> -- 
> Yours,
> Georg (STiAT)

-- 
With kind regards,
Sven



More information about the Pyrex mailing list