C++ Logo

std-proposals

Advanced search

Re: [std-proposals] statement expressions (was: "once" keyword)

From: Alejandro Colomar <alx.manpages_at_[hidden]>
Date: Wed, 24 May 2023 18:45:20 +0200
Hi Sebastian,

On 5/24/23 18:37, Sebastian Wittmeier via Std-Proposals wrote:
> Hi Alex,
>
>
> they are mentioned in § 3.7 of the cited paper as Prior Art. And are quite similar in many regards.
>
> Do you have an idea how they could be used for the use case of the OP?

They can't be used as gotos. It can only return by reaching the end of the
statement expression. So it doesn't have an equivalent to the 'do return'
of that proposal.

For the OP, I'd just go with goto, and use a compiler that allows it (GCC
allows it in C++2b mode).

Stmt exprs are useful for other things, such as creating macros that only
evaluate args once. Not sure how much this will be loved by C++ users,
but in C that means a lot.

Cheers,
Alex

>
>
> Best,
>
> Sebastian
>
> -----Ursprüngliche Nachricht-----
> Von:Alejandro Colomar <alx.manpages_at_[hidden]>
> Gesendet:Mi 24.05.2023 18:30
> Betreff:statement expressions (was: [std-proposals] "once" keyword)
> An:std-proposals_at_[hidden];
> CC:Sebastian Wittmeier <wittmeier_at_[hidden]>;
> Hi Sebastian,
>
> On 5/24/23 18:26, Sebastian Wittmeier via Std-Proposals wrote:
>> Perhaps something related to the proposed and actively discussed do expressions?
>>
>> Or they provide already enough functionality for your use case?
>>
>>
>> https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2806r1.html
>>
>> https://github.com/cplusplus/papers/issues/1462
>
> Hmm, how about statement expressions? They have been a GNU extension
> since forever, and are very useful. I use them all the time in C for
> writing safe macros.
>
> <https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html>
>
> I'd love to see those standardized, at least in ISO C, and hopefully
> also in C++.
>
> Cheers,
> Alex
>
>
>

Received on 2023-05-24 16:45:24