C++ Logo

std-proposals

Advanced search

Re: [std-proposals] !continue

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Thu, 9 Nov 2023 12:23:49 +0000
On Tue, Nov 7, 2023 at 12:14 PM sasho648 wrote:
>
> Anyone mentioned goto? - With goto you can do exactly what the OP is asking for:
>
> for ( ; SerialSimGsm.available(); ++p )
> rev_con:
> {
> if ( p >= &buf[sizeof(buf) - 1u] ) break;
> p[0u] = SerialSimGsm.read();
> p[1u] = '\0';
> unsigned const len = std::strlen(buf);
> char *ending = nullptr;
> if ( nullptr != (ending = std::strstr(buf, "\r\n")) )
> {
> ending[0u] = '\0';
> ending[1u] = '\0'; // Overwrite the "\r\n" with "\0\0"
> if ( ending != buf ) this->ProcessInput();
> buf[0u] = '\0';
> p = buf;
> goto rev_con; // Don't allow 'p' to be incremented
> }
> }



Your strategy causes an assertion failure in my code:

    https://godbolt.org/z/v6Px1Tao4

because your 'goto' is skipping the pre-iterative condition check.

Perhaps there should be four ways of continuing a loop:

    continue; // Don't skip anything
    continue(skip post); // Skip the post-iterative step
    continue(skip pre); // Skip the pre-iterative condition check
    continue(skip both); // Skip both the post-iterative
step and the pre-iterative condition check

The four words 'skip, pre, post, both' would not be keywords in the
C++ language, but would be words with special meaning only when
encountered in parentheses following 'continue'.

Received on 2023-11-09 12:24:02