This site has been retired. For up to date information, see handbook.gnome.org or gitlab.gnome.org.


[Home] [TitleIndex] [WordIndex

Vala Conditional Compilation Sample

A contrived example demonstrating conditional compilation usage and features. This is not a macro preprocessor.

void main () {

#if ( FOOBAR || FOO || BAR ) && (FOOBAR == FOO && FOO == BAR)
    message ("FOOBAR == FOO == BAR");
#endif

#if ! NOFOO && (FOOBAR || (FOO && BAR)) 
    message ("FOOBAR");
#elif FOO && ! NOFOO 
    message ("FOO");
#elif BAR && ! NOFOO
    message ("BAR");
#elif NOFOO
#if FOOBAR || (FOO && BAR)
    message ("NOFOO FOOBAR");
#else
    message ("NOFOO");
#endif
#else
    message ("Nothing relevant defined");
#endif

}

Compile and Run

$ valac -D FOOBAR conditional-compilation.vala
$ ./conditional-compilation
$ valac -D FOO -D BAR conditional-compilation.vala
$ ./conditional-compilation
$ valac -D FOO -D BAR -D FOOBAR -D NOFOO conditional-compilation.vala
$ ./conditional-compilation


Vala/Examples


2024-10-23 11:37