More from C++ Now 2014
bearophile via Digitalmars-d
digitalmars-d at puremagic.com
Sun May 18 15:29:03 PDT 2014
> "Undefined Behavior in C++; what is it, and why should I care":
> https://github.com/boostcon/cppnow_presentations_2014/blob/master/files/Undefined-Behavior.pdf?raw=true
> This reminds us to remove as much undefined behavior as
> possible from D.
Fixing some of those problems will break some D code. An example
from the slides pack:
void main() {
import std.stdio;
auto arr = [0, 2, 4, 6, 8];
int i = 1;
writeln(i + arr[++i] + arr[i++]);
}
It gives different results in dmd and ldc2:
...>dmd -wi -run temp.d
9
...>ldmd2 -wi -run temp.d
10
Hopefully no one writes code like that, but this situation can't
be accepted in a language that tries to be safer and better than
C/C++.
Bye,
bearophile
More information about the Digitalmars-d
mailing list