[Pyrex] Putting comments in C code

Lenard Lindstrom len-l at telus.net
Thu Dec 6 22:38:14 CET 2007


Greg Ewing wrote:
> Anand Patil wrote:
>   
>> Sorry, I'm trying to place 'pragmas' rather than comments.
>>     
>
> You might be able to do something with macros defined in
> a header, and call them from Pyrex as though they were
> functions.
>
>   

That will work with the C99 _Pragma, but not the older #pragma. Attempts 
to forgo the C header and declare a pragma entirely in Pyrex failed.

Attempt 1)

cdef extern from *:
    void _Pragma(char *s)

_Pragma('GCC dependency "prag.pyx"')

print "Hello"

Pyrex assigns the string literal to a global variable and passes the 
variable to _Pragma.
 
Attempt 2)

cdef extern from *:
    void _Pragma(char *s)
    char *pragma_prag_dep '"GCC dependency \"prag.pyx\""'

_Pragma(pragma_prag_dep)

print "Hello"

Pyrex strips the delimiting single quotes from the C specifier but then 
backslash escapes the double quotes as though the C specifier were a string.

-- 
Lenard Lindstrom
<len-l at telus.net>




More information about the Pyrex mailing list