[Pyrex] C++ forward declaration

Robert Bradshaw robertwb at math.washington.edu
Sat Apr 5 03:01:37 CEST 2008


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
> <len-l at telus.net>
>
>
> _______________________________________________
> Pyrex mailing list
> Pyrex at lists.copyleft.no
> http://lists.copyleft.no/mailman/listinfo/pyrex




More information about the Pyrex mailing list