Re: [Vala] Define constant at compile time
- From: Jan Hudec <bulb ucw cz>
- To: Anatol Pomozov <anatol pomozov gmail com>
- Cc: vala-list gnome org
- Subject: Re: [Vala] Define constant at compile time
- Date: Wed, 17 Nov 2010 12:08:49 +0100
On Tue, Nov 16, 2010 at 12:28:23 -0800, Anatol Pomozov wrote:
But what if you want to change the real constant value at the
compile-time? A classical example is DEBUG vs OPTIMIZED mode. During
development I want to log of information to stdout, like this:
if (DEBUG) {
stdout.printf("User ID is: $user");
}
and I don't want to have this code in the release version. To make it
happen one can use something like
bool DEBUG=false;
and compile the vala program with -DDEBUG (or its equivalent
-DDEBUG=true). This compiler flag changes the default value of the
const.
Type-safety means that vala compile knows that DEBUG is boolean and
complains if someone tries to use number/string here (-DDEBUG=foo) or
tries to set value for unexisting constant.
You know, vala DOES support THAT. Simply
#if DEBUG
stdout.printf("USer ID is: $user");
#endif
and than:
valac -DDEBUG ...
It is a flag -- either it's there or not.
--
Jan 'Bulb' Hudec <bulb ucw cz>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]