C++ Logo

liaison

Advanced search

Re: [wg14/wg21 liaison] Designated initializers in C++ and C

From: Martin Sebor <msebor_at_[hidden]>
Date: Wed, 12 Aug 2020 18:17:04 -0600
On 8/12/20 4:01 PM, Jens Maurer via Liaison wrote:
> On 12/08/2020 21.37, Jens Gustedt via Liaison wrote:
>> Since it seems that designated initializers are new in C++20, had that
>> particular property much been used before?
>
> Assuming you refer to defined ordering in something like
>
> int x = 0;
> int a[] = { x++, x++, x++ }; // 3 elements with values 0, 1, 2
>
> (with no designated initializers): yes, C++ code relies on it.

This could be a source of nasty bugs that C++ programmers used to
the stronger guarantee could introduce into C code they also work
on. To avoid those, WG14 should consider tightening up the C rules
to match. (It seems like we should track these things somehow as
they come up. An issues list like the one we kept for defect
reports would help.)

Martin

>
> The guaranteed ordering is used heavily when handling variadic
> templates iteratively (instead of recursively), for example
>
> template<class ... T>
> void g(T...args)
> {
> int dummy[] = { (f(args), 0) ... };
> }
>
> Here, we want to call f for each argument, in order.
>
> Jens
> _______________________________________________
> Liaison mailing list
> Liaison_at_[hidden]
> Subscription: https://lists.isocpp.org/mailman/listinfo.cgi/liaison
> Link to this post: http://lists.isocpp.org/liaison/2020/08/0178.php
>

Received on 2020-08-12 19:20:30