Re: [Vala] Conditional compilation: Passing #ifdefs through to generated C code



Le Mon, 23 Mar 2009 20:35:43 -0400,
Michael Terry <mike mterry name> a écrit :

I'd like to know more about how to use C preprocessor commands in
Vala.  I know that Vala allows some sort of conditional compilation
via [Conditional], but I'm interested in a particular use case that it
doesn't seem to really help with.

Specifically, I have a GTK+ app, and I want to use a bit of code only
if the compile-time GTK+ version is high enough.  So something like:

#if GTK_CHECK_VERSION(2, 4, 0)
    GtkFileChooserAction action;
    ...
#endif

I can have vala conditionally use a bit of code, but the conditional
is resolved at Vala-compile-time, not C-compile-time.  I need
'passthrough' conditionals that show up in the generated C code, since
my software distributes the C code in the release tarball.  The
typical user just compiles the C.

You have to run manually the source through cpp, it's a hack that
allows you to use #if's inside a Vala source. IMHO it is better to
tell on which Vala version you depend given the fact that Vala provides
Vapi files that may not work for older version of Gtk+.

If you really need to write code to be portable through different
versions, I suggest C. Don't take my word however, I don't know Vala
very well.

My 2 cents,
Mike



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]