checkedint call removal
John Colvin via Digitalmars-d
digitalmars-d at puremagic.com
Mon Jul 28 08:56:15 PDT 2014
On Monday, 28 July 2014 at 15:52:23 UTC, John Colvin wrote:
> On Monday, 28 July 2014 at 15:20:44 UTC, Ola Fosheim Grøstad
> wrote:
>> If asserts were used as optimization constraints
>
> all available code is fair game as optimisation constraints.
> What you are asking for is a special case for `assert` such
> that the optimiser is blind to it.
>
> bool foo(int a)
> {
> //let's handwrite a simple assert
> if(a >= 0)
> {
> exit(EXIT_FAILURE);
> }
> //and then do something.
> return a < 0;
> }
>
> Of course the compiler is free to rewrite that as
>
> bool foo(int a)
> {
> if(a >= 0)
> {
> exit(EXIT_FAILURE);
> }
> return true;
> }
>
> Why should the situation be different if I use the builtin
> `assert` instead?
admittedly this requires knowing that exit() won't return control
back to the function. With a dummy return it will still work
though:
bool foo(int a)
{
//let's handwrite a simple assert
if(a >= 0)
{
exit(EXIT_FAILURE);
return false; //dummy return
}
//and then do something.
return a < 0;
}
More information about the Digitalmars-d
mailing list