Thread overview | |||||
---|---|---|---|---|---|
|
March 07, 2008 no release-only version? | ||||
---|---|---|---|---|
| ||||
Am I right in thinking there's no built-in way to specify a block of code that gets disabled only in -release builds? This is how array bounds checking behaves, right? Always performed unless -release specified. But it seems there's no built-in version/debug statement that lets library code have the same behavior. The 'debug' condition is similar but it's only on in -debug builds, not in builds with specify neither -debug nor -release. --bb |
March 07, 2008 Re: no release-only version? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Bill Baxter | Bill Baxter Wrote:
> Am I right in thinking there's no built-in way to specify a block of code that gets disabled only in -release builds?
Days ago I was looking for the same thing.
At run time it's possible to know what you ask for (doesn't work in D 2.x, tan(0.9) is run in compile time, I presume):
import std.stdio: writefln;
import std.math: tan;
void main() {
bool release_mode = true;
try {
int[1] a;
int el = a[ cast(int)tan(0.9) ];
}
catch (Error e) {
release_mode = false;
}
writefln(release_mode);
}
But you can't use it in a static if.
Bye,
bearophile
|
March 08, 2008 Re: no release-only version? | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | bearophile wrote:
> Bill Baxter Wrote:
>> Am I right in thinking there's no built-in way to specify a block of code that gets disabled only in -release builds?
>
> Days ago I was looking for the same thing.
> At run time it's possible to know what you ask for (doesn't work in D 2.x, tan(0.9) is run in compile time, I presume):
>
> import std.stdio: writefln;
> import std.math: tan;
>
> void main() {
> bool release_mode = true;
> try {
> int[1] a;
> int el = a[ cast(int)tan(0.9) ];
> }
> catch (Error e) {
> release_mode = false;
> }
>
> writefln(release_mode);
> }
>
> But you can't use it in a static if.
>
> Bye,
> bearophile
Ha. I was afraid of an answer like that. :-)
--bb
|
Copyright © 1999-2021 by the D Language Foundation