www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Preconditions and Postconditions - selective enable/disable

reply Brother Bill <brotherbill mail.com> writes:
Can we ship our application to Production with Preconditions 
enabled, but with Postconditions and Invariants disabled?  If so, 
how to?

This would allow nervous managers to still have Preconditions 
active in Production, with slower performance.  After 3 months of 
it "just working", they can disable the Preconditions for better 
performance.
Nov 30
parent reply user1234 <user1234 12.de> writes:
On Monday, 1 December 2025 at 00:15:00 UTC, Brother Bill wrote:
 Can we ship our application to Production with Preconditions 
 enabled, but with Postconditions and Invariants disabled?  If 
 so, how to?

 This would allow nervous managers to still have Preconditions 
 active in Production, with slower performance.  After 3 months 
 of it "just working", they can disable the Preconditions for 
 better performance.
Yes, see https://dlang.org/dmd-linux.html#switch-check.
Nov 30
parent reply Brother Bill <brotherbill mail.com> writes:
On Monday, 1 December 2025 at 03:39:22 UTC, user1234 wrote:

 Yes, see https://dlang.org/dmd-linux.html#switch-check.
-check=[assert|bounds|in|invariant|out|switch ][=[on|off]] Overrides default, -boundscheck, -release and -unittest options to enable or disable specific checks. assert: assertion checking bounds: array bounds in: in contracts invariant: class/struct invariants out: out contracts switch: final switch failure checking on or not specified: specified check is enabled. off: specified check is disabled. If I wanted only in and switch "checked" would I add two -check arguments to CLI as ``` $ dub build -check=in=on -check=switch=on ``` or some other magic incantation?
Dec 01
parent Dejan Lekic <dejan.lekic gmail.com> writes:
On Monday, 1 December 2025 at 10:39:08 UTC, Brother Bill wrote:
 If I wanted only in and switch "checked" would I add two -check 
 arguments to CLI as
 ```
 $ dub build -check=in=on -check=switch=on
 ```

 or some other magic incantation?
One way is to export variable named DFLAGS with those options. Or, use dflags in your DUB config file - https://dub.pm/dub-reference/build_settings/#dflags
Dec 01