version(debug)
Jonathan M Davis
jmdavisProg at gmx.com
Sat Oct 6 11:23:13 PDT 2012
On Saturday, October 06, 2012 20:02:13 denizzzka wrote:
> huh, text should be from upper letter: Assert, Debug
No. Those are wrong. The code compiles, but those versions don't exist, so
they're not compiled in. A version(Assert) or version(Debug) block will never
be compiled in unless you define those versions. version(assert) is correct.
For instance, this prints "yes" without -release and "no" with -release:
import std.stdio;
void main()
{
version(assert)
{
writeln("yes");
}
else
{
writeln("no");
}
}
I am not seeing a compilation error with your example. What version of the
compiler are you using? Maybe version(assert) is new (I'd never heard of it
before), and your compiler is too old.
The only reason that you would see an error due to an invalid version
identifier would be if it's a keyword which isn't valid as a version identifier
(e.g. debug). The fact that the compiler doesn't know about a version
identifier doesn't produce an error. That just means that that particular block
of code isn't compiled in.
And debug isn't a valid version. It's not even in the list. The correct thing
to do is to a use a debug block. For instance, this code
import std.stdio;
void main()
{
debug
{
writeln("yes");
}
else
{
writeln("no");
}
}
will print "yes" when you compile with -debug and "no" otherwise.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list