Re: [Cython] [Pyrex] C++ forward declaration

Robert Bradshaw <[email protected]>
Newsgroups gmane.comp.python.cython.devel,gmane.comp.python.pyrex
Message-ID <[email protected]>
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
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.