June 08, 2005
Anders F Björklund wrote:
> This does not mean they are _ignored_ by the compiler, though,
> It still tries to parse them, so they need to be valid code...

This makes perfectly good/obvious sense.  My mistake/brainfart.

-- Chris Sauls
June 08, 2005
On Wed, 08 Jun 2005 18:14:22 +0000, clayasaurus wrote:

> zwang wrote:
>> <code>
>> void main(){
>>     debug int v;
>>     assert(!v);
>> }
>> </code>
>> 
>> dmd reports an "undefined identifier v" error when the -release switch is on.  Why does the compiler try to resolve "v" here?  Assert expressions are not supposed to be evaluated in release version, aren't they?
> 
> It also reports "undefined identifier v" without the release switch. Anyway, my suggestion is to use..
> 
> void main(){
>      debug int v;
>      debug assert(!v);
> }
> 
> If this is your desired behavior.

I occasionally use assert() outside of contract programming blocks. I code it as  ...

  debug {
      int v;
      assert(!v);
  }

or sometimes ...

   version(xyzzy) {
      int v;
      assert(!v);
  }

-- 
Derek Parnell
Melbourne, Australia
9/06/2005 7:33:06 AM
June 08, 2005
On Wed, 08 Jun 2005 11:14:48 -0700, Kyle Furlong wrote:

> Correct me if I am wrong, but I thought that when you compile -release all debug blocks are *ignored* by the compiler. That means that the:
> 
> debug int v; doesnt exist as far as the assert(!v) is concerned.
> 
> zwang wrote:
>> <code>
>> void main(){
>>     debug int v;
>>     assert(!v);
>> }
>> </code>
>> 
>> dmd reports an "undefined identifier v" error when the -release switch is on.  Why does the compiler try to resolve "v" here?  Assert expressions are not supposed to be evaluated in release version, aren't they?

debug() and -release have nothing whatsoever to do with each other. They
are completely independant.

debug() is only effected by the -debug switch. It is identical to version()
statements in effect.

-release switch cuts out 'in' and 'out' blocks, turns asserts() into NOPs, and doesn't generated array bounds checking and a few other 'safety' features.


-- 
Derek Parnell
Melbourne, Australia
9/06/2005 7:34:55 AM
June 08, 2005
On Wed, 08 Jun 2005 13:54:50 -0500, Chris Sauls wrote:

> Kyle Furlong wrote:
>> Correct me if I am wrong, but I thought that when you compile -release all debug blocks are *ignored* by the compiler.
> 
> You are right, but I believe the oddity here is that all 'assert' statements are also supposed to be ignored with the -release flag.  So there is no error, because neither the debug-decleration nor the assert actually exist when -release is given.

assert() is not ignored. It is parsed as normal. The difference is that
when -release is in effect, there is no generated code for assert().


-- 
Derek Parnell
Melbourne, Australia
9/06/2005 7:39:13 AM
June 08, 2005
Derek Parnell wrote:

> debug() and -release have nothing whatsoever to do with each other. They
> are completely independant.

This should probably be written in Big Red Ink somewhere,
since it's one of those things that trips all newcomers up.

Most are used to "Debug" and "Release" being opposites,
or two different build modes... (Release a.k.a. Final)


There is also a third build style in D, which is what you
get if you don't specify *either* of -debug nor -release.
That way, the ("heavy") debugging blocks are stripped out
but the contracts and the bounds checks are still left in.

I built a special version of Phobos like that, for checking
my own code against the contracts in the standard library...


Some people also find it confusing that the -debug / -release
doesn't affect the settings of -O (optimize) and -g (symbols).

That could probably also deserve a mentioning at the same time.
(maybe scribble it on the Wiki somewhere, to end up in the docs)

--anders
June 08, 2005
Derek Parnell wrote:

> I code it as  ...
> 
>   debug {
>       int v;
>       assert(!v);
>   }
> 
> or sometimes ...
> 
>    version(xyzzy) {
>       int v;
>       assert(!v);
>   }

You can also use the combined:

    debug(xyzzy) {
       int v;
       assert(!v);
   }

It's invoked as -debug=xyzzy


Might make it clearer that it
is debugging code, depending ?

--anders
June 08, 2005
On Thu, 09 Jun 2005 00:40:21 +0200, Anders F Björklund wrote:

> Derek Parnell wrote:
> 
>> I code it as  ...
>> 
>>   debug {
>>       int v;
>>       assert(!v);
>>   }
>> 
>> or sometimes ...
>> 
>>    version(xyzzy) {
>>       int v;
>>       assert(!v);
>>   }
> 
> You can also use the combined:
> 
>      debug(xyzzy) {
>         int v;
>         assert(!v);
>     }
> 
> It's invoked as -debug=xyzzy
> 
> Might make it clearer that it
> is debugging code, depending ?

Exactly my point, and Walter also said as much in the Docs. The version()
and the debug() statements have exactly the same effect, it just a matter
of communicating intent to the readers. Use debug() on stuff that is
intentionally not any part of any production code, and version() for
alternatives in application editions.

-- 
Derek
Melbourne, Australia
9/06/2005 9:27:50 AM
June 09, 2005
Anders F Björklund wrote:
> zwang wrote:
> 
>> <code>
>> void main(){
>>     debug int v;
>>     assert(!v);
>> }
>> </code>
>>
>> dmd reports an "undefined identifier v" error when the -release switch is on.  Why does the compiler try to resolve "v" here?  Assert expressions are not supposed to be evaluated in release version, aren't they?
> 
> 
> While both of "debug" (version) and "assert" (contract)
> should eventually be removed with the -release switch,
<snip>

Debug - no it shouldn't.  The -debug and -release options are completely independent of each other.

Assert - it already doesn't evaluate it.  But the compiler still semantically analyses it.

The compiler is correct - there's no such variable as v if -debug isn't specified.  Hence the OP's code doesn't make sense.

It would appear that the current semantic analyser doesn't support skipping assert expressions.  But you could also argue that it's logical, considering that -release is meant for once you know your program is working.  Even if DMD is wasting its time....

Stewart.

-- 
My e-mail is valid but not my primary mailbox.  Please keep replies on the 'group where everyone may benefit.
June 09, 2005
Stewart Gordon wrote:

>> While both of "debug" (version) and "assert" (contract)
>> should eventually be removed with the -release switch,
> 
> Debug - no it shouldn't.  The -debug and -release options are completely independent of each other.

OK, what was meant there was: "the lack of a -debug switch",
not the presence of the -release switch (which is unrelated)

--anders
1 2
Next ›   Last »