assume, assert, enforce, @safe

Daniel Murphy via Digitalmars-d digitalmars-d at puremagic.com
Fri Aug 1 06:26:58 PDT 2014


"Daniel Gibson"  wrote in message news:lrg0k5$1nl1$1 at digitalmars.com...

> I'd prefer language specifications *not* to include such parts.
> C wouldn't be any worse without the "you can eliminate writes to code 
> that's not read afterwards" part, for example.

Of course it would, that's why that's in there!!!

int *x = 0; // initialize just to be safe
...
x = ...;

You've just wasted a write.  Your program is now slower than it needs to be.

struct MyStruct s;
mystruct_init(&s);
s->field = something;
s->otherfield = somethingElse();

mystruct_init has to initialize all fields of s (to keep programmer suicide 
rates down) and yet you've just written over some of the values!  The 
compiler can clearly see that you never read from field and otherfield 
between the first write and the second. 



More information about the Digitalmars-d mailing list