digitalmars.D - proposal: should assert behave like static assert if its possible?
- dennis luehring <dl.soluz gmx.net> Jan 19 2008
- torhu <no spam.invalid> Jan 19 2008
- Walter Bright <newshound1 digitalmars.com> Jan 19 2008
- BCS <ao pathlink.com> Jan 19 2008
- dennis luehring <dl.soluz gmx.net> Jan 20 2008
- dennis luehring <dl.soluz gmx.net> Jan 21 2008
hi group,
this is one of my function needed to talk to an siemens plc(sps)
int byte_bit_to_int( int byte_, int bit_ )
{
// if bit_ is compiletime value
static assert( bit_ <= 7 );
// if bit_ is runtime value
assert( bit_ <= 7 );
return byte_*8+bit_;
}
and my question is how can i make the assert as save as possible
at compile- and runtime
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
ciao dennis
Jan 19 2008
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.
Jan 19 2008
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.
Jan 19 2008
Reply to Walter,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
need it to trigger at runtime, not compile time. So I think there would still be a way to do that.
it doesn't trigger at compile time.
How about have a flag that spits out a list of these as warnings? For sanity's sake it might skip assert(false).
Jan 19 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
Jan 20 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.
i know why it doesn't trigger at compiletime my question is - why can't you make it trigger at compiletime if the condition is false at compiletime we (just) need an replacement for assert(false) or assert(0) constructs, right? why don't replace this assert(false) constructs with just assert() ciao dennis
Jan 21 2008









BCS <ao pathlink.com> 