On Apr 4, 2008, at 3:21 PM, Lenard Lindstrom wrote:

> First, the Pyrex 0.9.6.4 compiler rejected the above code given by
> Robert Bradshaw. Second, even when altered to use function pointers  
> the
> generated code was wrong.

Sorry, I just hastily typed this up in my email to demonstrate the  
concept of forward declaration (which was the missing piece). Also,  
you're right about needing to do function pointers if you're using  
Pyrex.

> The global variable b was delcared as "B", not
> "MyNameSpace::B". This example corrects both problems:
>
> cdef extern from "B.h":
>      ctypedef struct B "MyNameSpace::B"
>
> cdef extern from "A.h":
>      ctypedef struct A "MyNameSpace::A":
>          void (* foo)(B data)
>
> cdef extern from "B.h":
>      ctypedef struct B "MyNameSpace::B":
>          void (* bar)(A data)
>
> cdef A a
> cdef B b
>
> # this will compile...but don't run it
> a.foo(b)
> b.bar(a)
>
> Note that B.h will be included before A.h in the generated C file.
>
> -- 
> Lenard Lindstrom
> <[EMAIL PROTECTED]>
>
>
> _______________________________________________
> Pyrex mailing list
> [EMAIL PROTECTED]
> http://lists.copyleft.no/mailman/listinfo/pyrex

_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to