digitalmars.D - version(assert)
- Peter Alexander (19/19) Sep 02 2012 The language spec says:
- =?UTF-8?B?QWxleCBSw7hubmUgUGV0ZXJzZW4=?= (8/25) Sep 02 2012 (Sorry, managed to reply directly via email with the previous message.)
- Peter Alexander (5/7) Sep 02 2012 Thanks, was going to do it myself if there was interest, but
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?
Sep 02 2012
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
Sep 02 2012
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...
Sep 02 2012








"Peter Alexander" <peter.alexander.au gmail.com>