Jump to page: 1 2
Thread overview
debug and assert
Jun 08, 2005
zwang
Jun 08, 2005
MicroWizard
Jun 08, 2005
zwang
Jun 09, 2005
Stewart Gordon
Jun 08, 2005
clayasaurus
Jun 08, 2005
Derek Parnell
Jun 08, 2005
Derek Parnell
Jun 08, 2005
Kyle Furlong
Jun 08, 2005
clayasaurus
Jun 08, 2005
Chris Sauls
Jun 08, 2005
Chris Sauls
Jun 08, 2005
Derek Parnell
Jun 08, 2005
Derek Parnell
June 08, 2005
<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?
June 08, 2005
>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?

No. Assert works where you placed it.
Of course you should place it in "unittest", "in" and "out" blocks.

Take a look into Contracts in D programming reference. http://www.digitalmars.com/d/dbc.html

Tamas Nagy


June 08, 2005
MicroWizard wrote:
>>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?
> 
> 
> No. Assert works where you placed it.
> Of course you should place it in "unittest", "in" and "out" blocks.
> 
> Take a look into Contracts in D programming reference.
> http://www.digitalmars.com/d/dbc.html
> 
> Tamas Nagy
> 
> 

It's not that obvious to me that asserts should always be placed in unittest{}, in{}, and out{} blocks.  Isn't it common to insert an assertion in the middle of a function?
June 08, 2005
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,
a simple way to make the program compile is to use:

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

Assuming that you do use -debug, for your debug build ?

--anders
June 08, 2005
zwang wrote:

> It's not that obvious to me that asserts should always be placed in unittest{}, in{}, and out{} blocks.  Isn't it common to insert an assertion in the middle of a function?

Me neither, assertions can (and should) be placed in the body as well.

It's supposed to throw different kinds of exceptions depending on
where it is encountered, but I don't think that's implemented yet.

--anders
June 08, 2005
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.
June 08, 2005
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?
June 08, 2005
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.
> 

No. the -debug and -release flags are not mutally exclusive, otherwise there would only be one flag, either -debug or -release.

> 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?
June 08, 2005
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.

-- Chris Sauls
June 08, 2005
Chris Sauls wrote:

> 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.

Both assert(), with the -release flag, and version(none) { }
are supposed to not actually generate any object code output.

This does not mean they are _ignored_ by the compiler, though,
It still tries to parse them, so they need to be valid code...


Derek ran into something similar while trying to version "!is".

--anders
« First   ‹ Prev
1 2