proposal: should assert behave like static assert if its possible?

dennis luehring dl.soluz at gmx.net
Sun Jan 20 00:19:37 PST 2008


Walter Bright schrieb:
> torhu wrote:
>> dennis luehring wrote:
>>> my question for walter is:
>>>
>>> can't assert behave like static assert if the value/condition is 
>>> available compiletime
>>>
>>> for example:
>>>
>>> int x = byte_bit_to_int( 7, 9 ); // an static assert could do the check
>>>
>>> int x = byte_bit_to_int( 7, random(8) ); // the normal assert is needed
>>
>> The problem is that sometimes you write things like assert(0), and 
>> need it to trigger at runtime, not compile time.  So I think there 
>> would still be a way to do that.
> 
> You're right (it's runtime flow of control sensitive), and that's why it 
> doesn't trigger at compile time.

an idea:

deprecate assert( static false ) constructs in one of the next releases
programmers need to replace it with assert() then

and later you can just activate this "assert behaves likes static assert 
if possible" feature - over night :-)

i think this feature will help a lot to get more stable programs out of 
D code

ciao dennis







More information about the Digitalmars-d mailing list