C++ Logo

STD-PROPOSALS

Advanced search

Subject: Re: [std-proposals] Remove infinite loop UB
From: Jason McKesson (jmckesson_at_[hidden])
Date: 2020-05-10 18:04:19


On Sun, May 10, 2020 at 3:43 PM connor horman via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> This would depend on the implementation of the VBLANK.
> I usually want to redraw the screen even if nothing changed.

Again, stop me if I'm wrong, but my understanding is that if your
VBlank routine doesn't do anything at all, doesn't touch CGRAM, VRAM,
OAM, or any PPU registers, the PPU will automatically render in accord
with what you had previously defined. AKA: it will "redraw the
screen".

If that's the case, I'm not sure I understand why a VBlank routine
could not be coded to simply return when the program has reached a
terminal condition.

> Also, I'd add that apparently C does not have/no longer has this issue(at least by C11, see
> http://port70.net/~nsz/c/c11/n1570.html#6.8.5p6). Where the loop condition of a for loop is a constant expression (empty conditions are included), the loop cannot be assumed to terminate. I can't see much of a reason for this to be different between the two languages.

I did some light research, and I found that C and C++ apparently
decided on different ways of dealing with the same issue. That issue
being that non-terminating code should be considered UB. See
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1528.htm for details.

The C11 approach only made it UB in a specific case: explicit looping
constructs. The WG14 N1528 paper doesn't cover `goto`-based infinite
loops, nor does it cover infinite tail recursion or other forms of
infinite looping.

By contrast, C++11 wording is a blanket statement of *visible* forward
progress. It doesn't care about the specific way you might fail to
achieve visible forward progress. It doesn't care about whether the
loop uses a constant expression or not. All that matters to the C++
wording is whether the code does anything that can be seen either from
another thread or from outside of the system.

So if anything, C++'s wording is better than C's wording. It certainly
covers the bases more.


STD-PROPOSALS list run by std-proposals-owner@lists.isocpp.org

Standard Proposals Archives on Google Groups