December 05, 2005
Anders F Björklund wrote:
> Oskar Linde wrote:
> 
>> I would very much prefer
>>
>> *(cast(byte *)0)=0;
>>
>> over
>>
>> assert(0);
>>
>> This would give a segmentation fault that the debugger would be able to catch and publish together with context (current stack). Even worse are runtime array index out of bounds error without even line number information...
> 
> 
> -release should give you a "halt"/crash instead -

So I should use -release to debug? ;)

> but you can also redefine your "_d_assert", from:
> extern (C) static void _d_assert(char[] filename, uint line)
> {
>     //printf("_d_assert(%s, %d)\n", cast(char *)filename, line);
>     AssertError a = new AssertError(filename, line);
>     //printf("assertion %p created\n", a);
>     throw a;
> }
> 
>  From http://www.digitalmars.com/techtips/unittests.html

That's useful, thanks!

/Oskar
December 05, 2005
Lionello Lunesu wrote:
> What would be handy though is the expression appearing in the assert error message. Then you could write "int no_return_value; assert(no_return_value);" and the printed message would contain "no_return_value" as a hint.
> 
> L.

It would indeed be handy, as one could even make it a bit more legible like so:

assert(some_boolean_expression && "this happened because...");

Then the executable would hopefully display the whole expression, from where the reason for the failure can be read. Of course, if it displays only the failed part (some_boolean_expression), this doesn't work. :-)
December 05, 2005
Oskar Linde wrote:>

> I would very much prefer
> 
> *(cast(byte *)0)=0;
> 
> over
> 
> assert(0);
> 
> This would give a segmentation fault that the debugger would be able to catch and publish together with context (current stack). Even worse are runtime array index out of bounds error without even line number information...

One of the first things I did in Ares was to make the assert handler overridable, for this exact reason:

void myHandler( char[] file, uint line )
{
    *(cast(byte *)0)=0;
}

// override handler
setAssertHandler( &myHandler );
...
// end override
setAssertHandler( null );


Sean
1 2
Next ›   Last »