checkedint call removal

Daniel Gibson via Digitalmars-d digitalmars-d at puremagic.com
Wed Jul 30 18:38:14 PDT 2014


Am 31.07.2014 02:50, schrieb Tobias Müller:
> Walter Bright <newshound2 at digitalmars.com> wrote:
>> On 7/30/2014 3:53 PM, Artur Skawina via Digitalmars-d wrote:
>>> No, with the assert definition you're proposing, it won't. It would
>>> be allowed to optimize away the bounds check. And this is just one of
>>> many problems with the assert==assume approach.
>>
>> Please explain how assume would behave any differently.
>
> It wouldn't and that's the point.
> If you have (a more harmless) assert _and_ assume you can still use assert,
> which would then _not_ allow those optimization.
>
> Tobi
>

I'm in favor of a "harmless" assert().
In C(++) I sometimes use things like

assert(x != NULL);

if(x != NULL) {
	x->foo = 42;
	// ...
}

I have that assertion to hopefully find bugs during development and fix 
them. However, no program is bug free and so it's totally possible that 
x *is* NULL in some circumstance in the wild (in a "release" mode 
binary), so I want to make sure it doesn't explode if that happens but 
handle the problem more gracefully.

It would be rather unfortunate if the compiler removed that second check 
in release mode because the assertion made it assume that x can't be NULL.

Cheers,
Daniel




More information about the Digitalmars-d mailing list