digitalmars.D - proposal: should assert behave like static assert if its possible?
- dennis luehring (19/19) Jan 19 2008 hi group,
- torhu (4/14) Jan 19 2008 The problem is that sometimes you write things like assert(0), and need
- Walter Bright (3/18) Jan 19 2008 You're right (it's runtime flow of control sensitive), and that's why it...
- BCS (3/27) Jan 19 2008 How about have a flag that spits out a list of these as warnings? For sa...
- dennis luehring (9/28) Jan 20 2008 an idea:
- dennis luehring (8/27) Jan 21 2008 i know why it doesn't trigger at compiletime
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 neededThe 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:You're right (it's runtime flow of control sensitive), and that's why it doesn't trigger at compile time.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 neededThe 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
Reply to Walter,torhu wrote:How about have a flag that spits out a list of these as warnings? For sanity's sake it might skip assert(false).dennis luehring wrote:You're right (it's runtime flow of control sensitive), and that's why it doesn't trigger at compile time.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 neededThe 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
Walter Bright schrieb:torhu wrote: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 dennisdennis luehring wrote:You're right (it's runtime flow of control sensitive), and that's why it doesn't trigger at compile time.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 neededThe 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 20 2008
Walter Bright schrieb:torhu wrote: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 dennisdennis luehring wrote:You're right (it's runtime flow of control sensitive), and that's why it doesn't trigger at compile time.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 neededThe 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 21 2008