Thread overview | |||||
---|---|---|---|---|---|
|
November 04, 2009 asserts in debug and release code | ||||
---|---|---|---|---|
| ||||
With respect to the dmd -release compiler switch, are assert statements meant to be compiled in release code? Whilst the D1 spec says "The compiler may optionally not evaluate assert expressions at all.", my intuition suggests that asserts would/should be evaluated (i.e. compiled in) when using -debug compiler switch and not when using the -release switch (and if neither switch who knows what***) *** And, btw, are -debug and -release mutually exclusive? If one desires asserts to be evaluated only in -debug, is the correct thing to prefix assert with debug as follows? debug assert(cond); Lastly, will assert/switch behaviour change in D2? Thanks for all help, Justin Johansson |
November 04, 2009 Re: asserts in debug and release code | ||||
---|---|---|---|---|
| ||||
Posted in reply to Justin Johansson | Hello Justin, > With respect to the dmd -release compiler switch, > are assert statements meant to be compiled in release code? > Whilst the D1 spec says "The compiler may optionally not evaluate > assert expressions at all.", > my intuition suggests that asserts would/should be evaluated (i.e. > compiled in) when using -debug -debug turns on debug{} sections > compiler switch and not when using the -release switch (and if neither > switch who knows what***) -release turns off asserts and bounds checks > *** And, btw, are -debug and -release mutually exclusive? No |
November 04, 2009 Re: asserts in debug and release code | ||||
---|---|---|---|---|
| ||||
Posted in reply to BCS | BCS Wrote:
> Hello Justin,
>
> > With respect to the dmd -release compiler switch,
> > are assert statements meant to be compiled in release code?
> > Whilst the D1 spec says "The compiler may optionally not evaluate
> > assert expressions at all.",
> > my intuition suggests that asserts would/should be evaluated (i.e.
> > compiled in) when using -debug
>
> -debug turns on debug{} sections
>
> > compiler switch and not when using the -release switch (and if neither
> > switch who knows what***)
>
> -release turns off asserts and bounds checks
Thanks BCS for reply.
Initially I thought something was odd as (using Digital Mars D Compiler v1.050)
my asserts were firing even with -release switch but just now realised
had -unittest flicked as well. So in summary this is the observation:
(no -debug or -release) leaves asserts on (consistent with what you say)
-debug -release flicks asserts off (consistent with what you say)
-unittest -release leaves asserts on :-)
So -unittest takes precedence over -release wrt asserts. Okay, that seems reasonable.
beers
Justin
|
Copyright © 1999-2021 by the D Language Foundation