Python cryptography, Rust, and Gentoo
Python cryptography, Rust, and Gentoo
Posted Feb 12, 2021 10:55 UTC (Fri) by khim (subscriber, #9252)In reply to: Python cryptography, Rust, and Gentoo by Wol
Parent article: Python cryptography, Rust, and Gentoo
> undefined behaviour is whatever the hardware does
If that is the definition behavior then what the heck is implementation-defined behavior?
No, the confusion is much deeper. “Undefined behavior” always meant what it means today. And, in fact, most types of undefined behavior don't cause any confusion. Attempts to read from pointer after calling free or reading from undefined variable rarely cause confusion.
Something like this:
int foo() {
int i;
i = 42;
}
int bar() {
int i;
return i;
}
int main() {
foo();
printf("%d\n", bar());
}
Should code like above work or not? Clang breaks it even when compiled with -O0 (but gcc with -O0 works, although any other optimization level breaks it).
I don't know any practicing programmer who says compilers should support code like the above example.
Tragedy happened when decisions of C standards committee clashed with developer's expectations. Because C was designed to create portable programs lots of things which are, actually, well-defined (yet different!) on many platforms were put into “undefined behavior, don't use” bucket (instead of “implementation-defined, use carefully” bucket).
The intention was, of course, to make programs portable, but completely different things happened instead: so many “implementation-defined, use carefully” things were marked as “undefined behavior”s that developers started thinking that “undefined behavior” means precisely that: whatever the hardware does.
And now we have all that mess.
But no, “undefined behavior” never meant whatever the hardware does. Not even in C89. It was always “something your program should never do.”
