3 ms·
What you write is perfectly plausible, and yet you're wrong. Such is the magic of the C++ standard ;) There is a part of the C++ standard that says something a
by nhaehnle 13y ago
What you write is perfectly plausible, and yet you're wrong. Such is the magic of the C++ standard ;)
There is a part of the C++ standard that says something along the lines of: the compiler may assume that every program will eventually exhibit some side-effect. That part of the standard also explicitly states that this is intended to allow compilers to remove loops with empty bodies (or bodies with only dead code) even if they cannot prove termination of the loop. See e.g. page 14 of http://isocpp.org/files/papers/N3690.pdf http://isocpp.org/files/papers/N3690.pdf
This is certainly useful when you think of code that is created indirectly via macros and/or template instantiation. Whether compilers actually perform this "optimization" on explicit endless loops like for(;;); is another question, but at least C++ can claim to be able to run certain endless loops in under a second ;)
- knz42 13y agoWait a second. The document you link to is a working draft for the next ISO C++ standard, which is by no means yet finalized (planned for 2014 or 2017?). The 2011 standard does not contain any wording to the same effect. Again I would be surprised if this specific paragraph makes it to the final version. Then the initial discussion above was about C, and the ISO C standard does not contains words to that effect at all.