Re: unnamed stucts

Brad Schick <[email protected]>
Newsgroups gmane.comp.python.pyrex
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.