Date: Thu, 9 Nov 2023 17:16:28 +0200
Do:
for ( ; ; ++p )
while(SerialSimGsm.available())
{
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;
continue;
}
break;
}
On Thu, Nov 9, 2023 at 5:10 PM sasho648 <sasho648_at_[hidden]> wrote:
> Yeah that's fair - didn't think this through - well just don't use for
> then.
>
> On Thu, Nov 9, 2023 at 2:24 PM Frederick Virchanza Gotham via
> Std-Proposals <std-proposals_at_[hidden]> wrote:
>
>> 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'.
>> --
>> Std-Proposals mailing list
>> Std-Proposals_at_[hidden]
>> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>>
>
for ( ; ; ++p )
while(SerialSimGsm.available())
{
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;
continue;
}
break;
}
On Thu, Nov 9, 2023 at 5:10 PM sasho648 <sasho648_at_[hidden]> wrote:
> Yeah that's fair - didn't think this through - well just don't use for
> then.
>
> On Thu, Nov 9, 2023 at 2:24 PM Frederick Virchanza Gotham via
> Std-Proposals <std-proposals_at_[hidden]> wrote:
>
>> 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'.
>> --
>> Std-Proposals mailing list
>> Std-Proposals_at_[hidden]
>> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>>
>
Received on 2023-11-09 15:16:41