Thread overview | |||||
---|---|---|---|---|---|
|
September 02, 2012 version(assert) | ||||
---|---|---|---|---|
| ||||
The language spec says: "The compiler may optionally not evaluate assert expressions at all." In practice, this means that it depends on compiler flags. For DMD, assert expressions are ignored in -release. Sometimes, I want to do things only when asserts are being compiled, for example: version(release) {} else import std.format; assert(x == 0, format("x is %d, not 0", x)); I have two problems with this: 1. It's ugly to use the version... else syntax. 2. It's tied to the fact that DMD doesn't compile asserts in release. What I would prefer: version(assert) import std.format; Of course, version(assert) is compiled when asserts are compiled. This makes the intent clear, and removes coupling with particular compiler options. Thoughts? |
September 02, 2012 Re: version(assert) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Peter Alexander | On 02-09-2012 13:39, Peter Alexander wrote: > The language spec says: > > "The compiler may optionally not evaluate assert expressions at all." > > In practice, this means that it depends on compiler flags. For DMD, > assert expressions are ignored in -release. > > Sometimes, I want to do things only when asserts are being compiled, for > example: > > version(release) {} else import std.format; > assert(x == 0, format("x is %d, not 0", x)); > > > I have two problems with this: > > 1. It's ugly to use the version... else syntax. > 2. It's tied to the fact that DMD doesn't compile asserts in release. > > What I would prefer: > > version(assert) import std.format; > > > Of course, version(assert) is compiled when asserts are compiled. > > This makes the intent clear, and removes coupling with particular > compiler options. > > Thoughts? (Sorry, managed to reply directly via email with the previous message.) Yes: https://github.com/D-Programming-Language/dmd/pull/1099 (If that's accepted, I'll send patches to GDC and LDC as well.) -- Alex Rønne Petersen alex@lycus.org http://lycus.org |
September 02, 2012 Re: version(assert) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alex Rønne Petersen | On Sunday, 2 September 2012 at 12:49:39 UTC, Alex Rønne Petersen
wrote:
> Yes: https://github.com/D-Programming-Language/dmd/pull/1099
>
> (If that's accepted, I'll send patches to GDC and LDC as well.)
Thanks, was going to do it myself if there was interest, but
you've saved me the effort :-)
Also, I have now realised that version(release) doesn't work...
|
Copyright © 1999-2021 by the D Language Foundation