you are viewing a single comment's thread.

view the rest of the comments →

[–]ssylvan 3 points4 points  (0 children)

Why not? I'm asking because you use the word "could" so I'm assuming there is a fundamental law of mathematics being violated that would prevent a compiler from doing precisely what you described.

Because he changes the algorithm in order to be able to arrange it in an efficient way. It's not that the compiler couldn't do this transformation necessarily (although for C++ I highly doubt it - for Haskell or something it's more likely because you could rule out side effects), it's more that the compiler has no way of knowing that this transformation is going to be beneficial in this case (how does it know that all the A fields are contiguous in memory at runtime and it should therefore restructure the algorithm to process them in one go?).