Conditional compilation for non-release version

Timon Gehr timon.gehr at gmx.ch
Sat Apr 28 05:58:42 PDT 2012


On 04/28/2012 02:05 PM, Joseph Rushton Wakeling wrote:
> Hello all,
>
> I've just been reading through this page: http://dlang.org/version.html
>
> Is there a way to put in place a conditional segment of code that is
> included if the code is _not_ compiled with the -release flag?
>
> Of course I can put in a debug statement, but that would require me to
> compile with -debug. I'd like the opposite, that unless I explicitly
> specify the code as release-ready, the specified set of checks will be
> performed.
>
> The reason I'm asking is because the checks I want to perform are of the
> form,
>
> foreach(x; myVeryLargeArray) {
> assert(/* ... some condition about x */);
> }
>
> ... and I'm concerned that with the foreach() loop in place, it will
> slow down the code even if the assert() statements are ignored at
> compile time. So I'd like to be able to do something instead like,
>
> version(!release)
> {
> foreach(x; myVeryLargeArray) {
> assert(/* ... some condition about x */);
> }
> }
>
> ... is this possible?
>
> Thanks & best wishes,
>
> -- Joe


assert({
   /* code you want to execute in non-release mode */
   return true;
}());


More information about the Digitalmars-d-learn mailing list