D - Unsafe and doomed

H. S. Teoh hsteoh at quickfur.ath.cx
Sun Jan 5 19:25:49 PST 2014


On Sun, Jan 05, 2014 at 06:03:04PM -0800, Walter Bright wrote:
> On 1/5/2014 4:20 PM, deadalnix wrote:
> >On Monday, 6 January 2014 at 00:13:19 UTC, Walter Bright wrote:
> >>I'd still like to see an example, even a contrived one.
> >
> >void foo(int* ptr) {
> >     *ptr;
> >     if (ptr is null) {
> >         // do stuff
> >     }
> >
> >     // do stuff.
> >}
[...]
> If you're writing code where you expect undefined behavior to cause a
> crash, then that code has faulty assumptions.
> 
> This is why many languages work to eliminate undefined behavior -
> but still, as a professional programmer, you should not be relying
> on undefined behavior, and it is not the optimizer's fault if you
> did. If you deliberately rely on UB (and I do on occasion) then you
> should be prepared to take your lumps if the compiler changes.

On that note, some time last year I fixed a bug in std.bigint where a
division by zero was deliberately triggered with the assumption that it
will cause an exception / trap. But it didn't, so the code caused a
malfunction further on, since control passed on to where the original
author assumed it wouldn't.


T

-- 
Philosophy: how to make a career out of daydreaming.


More information about the Digitalmars-d mailing list