So I\'m arguing with my friend who claims that a compiler like GCC can detect a pure function automatically without any type information. I doubt that.
Languages lik
I discovered while writing an article comparing C# and C++ performance that Visual C++ can indeed detect a pure function of moderate complexity, while calling a function that computed a polynomial.
I called the polynomial function in a loop to eat up time on the clock. The compiler optimized the call to run once before the loop started and re-use the result within the loop. To do that it would have to know that there are no side-effects.
I must say though, is nice to be able to guarantee that the compiler can do an optimization, by marking a function as pure, and it serves as a form of documentation, too.