assert(0) behavior

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Wed Aug 5 01:46:29 PDT 2015


On Wednesday, 5 August 2015 at 08:09:49 UTC, Joseph Rushton 
Wakeling wrote:
> On Monday, 3 August 2015 at 23:57:36 UTC, Steven Schveighoffer 
> wrote:
>> At the very least, assert(0, "message") should be a compiler 
>> error, the message is unused information.
>
> Only if you compile in -release mode.  Without wanting to get 
> into a bikeshedding debate, I think that flag name may be 
> mislead: it's not about release vs. development, it's about the 
> tradeoff you are making between speed and safety.

That's arguably true, but historically, release builds are where 
you turn off assertions and turn on optimizations. So, it does 
pretty much what most folks would expect from a release build 
(though some folks might assume that it turns on optimizations as 
well, which it doesn't). Now, there are good reasons to leave 
assertions in in release builds, but then you're arguably just 
using your debug builds in production (probably because you don't 
need the efficiency gain and are too paranoid to risk turning the 
assertions off).

So, you have a good point, but really, -release does with 
assertions what's normally expected of release builds, so I don't 
think that it's actually misleading at all.

- Jonathan M Davis


More information about the Digitalmars-d mailing list