Just hope you never need to build your Cython-generated code with a C
compiler that does not accept C++-style comments  ;-)

Seriously, such a feature would be really useful. I've never made a
serious proposition just because I cannot figure out a "cythonic"
syntax for this... Perhaps somethig like

include verbatim """
<C code>
"""



On Sat, Feb 7, 2009 at 8:46 PM, William Stein <[email protected]> wrote:
> On Sat, Feb 7, 2009 at 3:21 PM, Lisandro Dalcin <[email protected]> wrote:
>> BTW,  a feature I really miss from the times I was a heavy SWIG user
>> is the ability to include verbatim C code snipets...
>>
>
> Warning: blatant hack below; just for fun.
>
> You can put verbatim C code snippets in Cython by abusing cdef extern.
>  Here is an example that illustrates doing this to wrap some C++ code.
>  I wanted to put the verbatim C++ code "a[b]=c" in, so I did it like
> so.  You
> could put any C/C++ code inside that macros though, not just a[b]=c.
>
> cdef extern from "vector.h":
>    ctypedef struct intvec "std::vector<unsigned int>":
>        int get_entry "operator[]"(int n)
>    intvec intvec_factory "std::vector<unsigned int>"(int len)
>
> cdef extern from "":
>    void DEFINE_SET "#define SET(a,b,c) a[b]=c; //"()
>    void SET(intvec, int, int)
>
> DEFINE_SET()
>
> cdef intvec v = intvec_factory(10)
> SET(v,2,399283)
> print v.get_entry(2)
>
> Obviously you should never do this :-)
>
>  -- William
> _______________________________________________
> Cython-dev mailing list
> [email protected]
> http://codespeak.net/mailman/listinfo/cython-dev
>



-- 
Lisandro Dalcín
---------------
Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC)
Instituto de Desarrollo Tecnológico para la Industria Química (INTEC)
Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET)
PTLC - Güemes 3450, (3000) Santa Fe, Argentina
Tel/Fax: +54-(0)342-451.1594
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to