logoalt Hacker News

mort96yesterday at 5:19 PM3 repliesview on HN

If the semantics of 'while (true)' was "will crash the program after an implementation-defined but often fairly low number of iterations", I would stop using 'while (true)'.


Replies

leni536yesterday at 8:15 PM

Precisely. ISO C and C++ have a notion of various implementation limits, one of which is nested function calls due to exhausting the stack. TCO could be about a carveout on this limit.

Having said that the standards give way too much leeway for the limits, so a conforming implementation might have arbitrary limits for loops as well (at least in C++, I'm not that familiar with the C standard's wording).

cmovqyesterday at 5:47 PM

Note that compilers are more than happy to delete 'while (true)' if the loop doesn't have side-effects.

show 2 replies
layer8yesterday at 6:39 PM

It’s precisely not the semantics of the program that will crash the program, but the behavior of the language implementation. It’s similar to when a program in a GC language fails with OOM because the language implementation uses a no-op collector. That’s usually not part of programming language semantics.

show 3 replies