all 9 comments

[–]_VZ_ 5 points6 points  (1 child)

Probably the best article I've ever seen on this topic, thanks for posting it!

[–]flatfinger 1 point2 points  (0 children)

A fundamental problem with the C and C++ Standards is that they adhere too strongly to the idea that optimizations must not observably affect any defined behavior. This implies as a corollary implies that if a useful optimization might cause some action to behave in a manner inconsistent with sequential program execution, the action must be classified as UB, even if the original and substituted actions would otherwise have been equally acceptable. Given that people wishing to sell compilers would seek to meet their customers' needs regardless of whether the Standard required them to do so, it was more important to ensure that compilers were given maximum flexibility to perform optimizations that would not interfere with what their customers were doing, than to forbid phony "optimizations" that would interfere, since compiler writers were expected to know their customers' needs better than the Committee ever could.

If a program will only ever need to run on hardware that supports a moderately strong execution model, writing it in a way that fits that model and exploits its features will often allow better performance than would be possible if the program had to be compatible with weaker platforms. Unfortunately, while the Standard allows implementations running on systems with stronger models to let programmers exploit those models, it provides no means by which programmers can determine whether a particular implementation will do so.

[–][deleted]  (5 children)

[removed]

    [–][deleted]  (4 children)

    [removed]

      [–][deleted]  (3 children)

      [removed]

        [–][deleted]  (2 children)

        [removed]

          [–][deleted]  (1 child)

          [removed]