July 16, 2004 Re: condition stringising in assert | ||||
---|---|---|---|---|
| ||||
Posted in reply to Matthew Wilson | Matthew Wilson wrote: > Can I register yet another request for this long-looked-for feature? > > I'm finding it rather painful that the output just prints "Error: > AssertError Failure vector(390)". It's just a PITA. > > Can we get this for 1.0? > > You can do it right now. #define ASSERT(x) if(!(x)) __assert_fail("Assertion failed: " ~ #x); And then, pass your D source thru your favorite C preprocessor first. (You don't have to avoid CPP. There's nothing wrong with it.) |
July 16, 2004 Re: condition stringising in assert | ||||
---|---|---|---|---|
| ||||
Posted in reply to Carlos Santander B. | Carlos Santander B. wrote: >"Bent Rasmussen" <exo@bent-rasmussen.info> escribió en el mensaje >news:cd6nm7$2ddq$1@digitaldaemon.com >| I interpret assertions as a subtyping mechanism. E.g. the expression >| >| x >= 0 >| >| is an implicit construction of the type "natural", on a conceptual level. >| Its not as safe as compile time checking but useful nonetheless. >| > >read below > >| It seems appropriate to use an assertion here. Defensive programming still >| has its place and probably beyond input validation for critical systems; >no >| experience there though. :-) >| >| I don't know though, if it is possible to catch an assertion violation as >an >| exception. That appears to be useful to me. Then if an assertion violation >| is caught then the assertion would not be turned off in the release build. >| But since assertions have no labels in D, it wouldn't be possible to catch >a >| particular assertion violation, e.g. as in >| >| sqrt(Int x): Int >| require >| natural: x >= x.Zero >| >| Just a thought... > >It'd be better (and easier for the programmers) if D had ranges. Then you >would declare your own natural type with that condition. And it'd be compile >time. > >----------------------- >Carlos Santander Bernal > > > > Agreed, its one of the things I liked about ada. -- -Anderson: http://badmama.com.au/~anderson/ |
Copyright © 1999-2021 by the D Language Foundation