Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Can a sufficiently smart compiler figure out that a function is pure automatically?

0
Posted

Can a sufficiently smart compiler figure out that a function is pure automatically?

0

The problems with the sufficently smart compiler argument are: • most functions call other functions, which call other functions, until one of them calls a library routine whose source is not available to the compiler. So it will have to assume it is not pure. With a pure function attribute, external library functions that are pure can be marked as pure, and then the analysis can work for enough cases to be useful. • Since virtual functions (and by extension delegates and function pointers) can be extended by the user at times the compiler won’t see it, they have to be assumed to be impure. • If the programmer intends for a particular function to be pure and the compiler detects it is not, this may go unnoticed by the programmer. Even worse, if the programmer does notice it, it may be arbitrarily difficult to determine why the compiler thinks it is impure – is it a programming mistake or a compiler bug?

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123