ifdef macros with cython not possible?

530 views
Skip to first unread message

René Dudfield

unread,
Jun 17, 2019, 10:46:19 AM6/17/19
to cython...@googlegroups.com
Hello,

Is there a nice way to use macros for feature selection with cython?

For example, I would like to use this macro at C compile time (not cython compile time).

#if defined(SDL_VERSION_ATLEAST)
#if (SDL_VERSION_ATLEAST(2, 0, 5))
                SDL_SetWindowResizable(win, flags & PGS_RESIZABLE);
#endif
#endif

It seems the best way available is to make a .h/.c file(s) that do all the pre-processor magic, then use that from cython.

Happy to hear any other methods.


cheerio,

Stefan Behnel

unread,
Jun 23, 2019, 5:22:06 AM6/23/19
to cython...@googlegroups.com
René Dudfield schrieb am 17.06.19 um 08:59:
> Is there a nice way to use macros for feature selection with cython?
>
> For example, I would like to use this macro at C compile time (not cython
> compile time).
>
> #if defined(SDL_VERSION_ATLEAST)
> #if (SDL_VERSION_ATLEAST(2, 0, 5))
> SDL_SetWindowResizable(win, flags & PGS_RESIZABLE);
> #endif
> #endif
>
> It seems the best way available is to make a .h/.c file(s) that do all the
> pre-processor magic, then use that from cython.

Yes, that's pretty much how you'd do it, also because you would normally
want these decisions to be taken by the C compiler and not by Cython. You
could define a C macro or inline function that adapts to the defines, and
then call that from your Cython code.

You can write this glue code inside of your Cython file, though:

http://docs.cython.org/en/latest/src/userguide/external_C_code.html#including-verbatim-c-code

Stefan

René Dudfield

unread,
Jun 27, 2019, 3:16:03 AM6/27/19
to cython...@googlegroups.com
Thank you :)
Reply all
Reply to author
Forward
0 new messages