View mode: basic / threaded / horizontal-split · Log in · Help
October 06, 2012
version(debug)
Why

version(assert){ int i = 1; } else { int k = 1; }

causes error:
Error: identifier or integer expected, not assert
?

This is bug or feature?
http://dlang.org/version.html says what it is correct code, 
because "assert" in the list of "Predefined Version Identifiers"

How I can solve this problem by other way?
October 06, 2012
Re: version(debug)
huh, text should be from upper letter: Assert, Debug
October 06, 2012
Re: version(debug)
On 10/6/12, denizzzka <4denizzz@gmail.com> wrote:
> This is bug or feature?
> http://dlang.org/version.html says what it is correct code,
> because "assert" in the list of "Predefined Version Identifiers"

I think that must be a typo on the website. Use version(debug) instead.
October 06, 2012
Re: version(debug)
Strange, when you write to the forum then you solve problem 
immediately by yourself :-)

Thx for fast answers!
October 06, 2012
Re: version(debug)
On Saturday, 6 October 2012 at 18:15:49 UTC, Andrej Mitrovic
wrote:
> On 10/6/12, denizzzka <4denizzz@gmail.com> wrote:
>> This is bug or feature?
>> http://dlang.org/version.html says what it is correct code,
>> because "assert" in the list of "Predefined Version 
>> Identifiers"
>
> I think that must be a typo on the website. Use version(debug) 
> instead.

No, debug also don't works. Debug and Assert works fine
October 06, 2012
Re: version(debug)
On 10/6/12, denizzzka <4denizzz@gmail.com> wrote:
> No, debug also don't works. Debug and Assert works fine

Oh right, I was thinking of this:
debug
{
   // blabla
}

I don't even know why there is a version(Debug) when you can use a debug block.
October 06, 2012
Re: version(debug)
On 10/6/12, denizzzka <4denizzz@gmail.com> wrote:
> Strange, when you write to the forum then you solve problem
> immediately by yourself :-)

That happens to me all the time too. :)
October 06, 2012
Re: version(debug)
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
October 06, 2012
Re: version(debug)
On Saturday, October 06, 2012 20:21:52 Andrej Mitrovic wrote:
> I don't even know why there is a version(Debug) when you can use a debug
> block.

There isn't. It's just that it compiles because Debug isn't a keyword. The 
code within a version(Debug) block won't be compiled in unless you define such 
a version yourself.

- Jonathan M Davis
October 06, 2012
Re: version(debug)
On 06-10-2012 20:23, Jonathan M Davis wrote:
> 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
>

version (assert) is a very recent addition to the compiler and is not in 
2.060.

-- 
Alex Rønne Petersen
alex@lycus.org
http://lycus.org
« First   ‹ Prev
1 2
Top | Discussion index | About this forum | D home