▲ | davidrupp 5 days ago | |||||||
> A modern compiler embeds a considerable degree of probabilistic behaviour. Can you give some examples? | ||||||||
▲ | hn_acc1 5 days ago | parent | next [-] | |||||||
There are pragmas you can give to a compiler to tell it to "expect that this code path is (almost) never followed". I.e. if you have an assert on nullptr, for example. You want it to assume the assert rarely gets triggered, and highly optimize instruction scheduling / memory access for the "not nullptr" case, but still assert (even if it's really, REALLY slow, relatively speaking) to handle the nullptr case. | ||||||||
▲ | glitchc 4 days ago | parent | prev | next [-] | |||||||
Any time the language specification is undefined, the compiler behaviour will be probabilistic at best. Here's an example for C: | ||||||||
▲ | WD-42 5 days ago | parent | prev | next [-] | |||||||
I keep hearing this but it’s a head scratcher. They might be thinking of branch prediction, but that’s a function of the cpu, not the compiler. | ||||||||
▲ | ModernMech 5 days ago | parent | prev [-] | |||||||
It’s not that they embed probabilistic behavior per se. But more like they are chaotic systems, in that a slight change of input can drastically change the output. But ideally, good compiler design is idempotent — given the same input, the output should always be the same. If that were not generally true, programming would be much harder than it is. | ||||||||
|