[Pyrex] Conditional compilation

khinsen at cea.fr khinsen at cea.fr
Tue Apr 5 09:45:08 CEST 2005

On 05.04.2005, at 02:06, David M. Cooke wrote:

> AFAIK, there's no way to do the equivalent of #ifdef. You can try to
> fake it with header files and compile-time optimization, though. If

Header files, yes, but relying on compile-time optimization is risky if  
one cares at all about portability. In many cases, the code to be  
"switched off" would be incorrect (e.g. using undefined data types)  
when the condition is not fulfilled. Many if not most compilers would  
check the code for correctness even if it were ultimately optimized  

As for the header file approach, I think this quickly becomes a mess.  
Take the most common thread-related code in Python:  
they do nothing - that's easy to emulate using function-style macros in  
a header file. But with WITH_THREAD, they expand into a pair of braces  
inside which a temporary variable is defined. This implies restrictions  
on the syntax of the code in between them, which I can't expect Pyrex  
to satisfy. In fact it doesn't.

Has anyone tried using cpp on Pyrex code? My main worry is if the  
preprocessor maintains indentation, on all platforms. Perhaps it is  
easier to write a preprocessor in Python instead.

Konrad Hinsen
Laboratoire Leon Brillouin, CEA Saclay,
91191 Gif-sur-Yvette Cedex, France
Tel.: +33-1 69 08 79 25
Fax: +33-1 69 08 82 61
E-Mail: khinsen at cea.fr

More information about the Pyrex mailing list