[Pyrex] unnamed stucts

Brad Schick schickb at gmail.com
Thu May 8 06:18:13 CEST 2008


On 05/07/2008 06:01 PM, Greg Ewing wrote:
> Brad Schick wrote:
>> If I extract the nested stuct declarations and give them names, I assume
>> the generated C would not compile correctly since it will #include the
>> original nameless C declaration.
>
> It should work okay as long as you don't use the names for
> anything other than declaring the nested struct members.
> The C code for accessing members of the inner structs is
> the same whether they're declared in a nested manner or not.
>

Thanks for the feedback, but I don't follow. Pyrex won't
compile the code unless I use the names of the nested structs to
reference their elements. If you take my original C example and 
create this pyrex code for it:

cdef extern from "header.h":
    ctypedef struct inner1:
       unsigned lo
       unsigned hi

    ctypedef struct inner2:
       unsigned short lobytes[4]
       unsigned short hibytes[4]

    ctypedef union nonce_t:
        inner1 in1
        inner2 in2
        unsigned char bytes[8]

def func():
    cdef nonce_t nonce
    print nonce.lo      # won't compile in pyrex
    print nonce.in1.lo  # won' compile in C

You have problems. The only ways I see to make this work are either
forgoing the convenience of a union (and just working with one of the
alternatives) or doing some ugly casting. Or have I missed something?

-Brad




More information about the Pyrex mailing list