Friendly-C

via Digitalmars-d digitalmars-d at puremagic.com
Fri Aug 29 13:41:33 PDT 2014


On Friday, 29 August 2014 at 18:46:20 UTC, Marc Schütz wrote:
> It does. An access that can potentially fault is more or less 
> equivalent to this:
>
>     if(p is null)
>         throw new Error();
>     *p = ...;
>
> When you remove the access, you're removing the test, which 
> changes program semantics.

No, if the access can trap unexpectedly then the program was 
incorrect to begin with. A deliberate exception is not the same 
as an unexpected trap. Removing the reason for the unexpected 
trap does not make the program more incorrect. So you don't 
change the semantics of a correct program, you only change when 
an incorrect program is classified as incorrect.

If the semantics is that of nondeterministic evaluation then a 
fault (bottom) might not be incorrect, you might mitigate 
exceptional partial results if you can find another path that 
does not lead to an exception.

Like this:

return select( f(x) or g(x) or h(x) )

It is sufficient here that just one of f, g, and h produces a 
valid result, the other ones might go down into infinite 
recursion or whatever.


More information about the Digitalmars-d mailing list