C++ Logo

liaison

Advanced search

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

From: Jens Gustedt <jens.gustedt_at_[hidden]>
Date: Wed, 12 Aug 2020 21:37:00 +0200
Nevin,

on Wed, 12 Aug 2020 14:07:30 -0500 you (Nevin Liber via Liaison
<liaison_at_[hidden]>) wrote:

> On Wed, Aug 12, 2020 at 12:24 PM Florian Weimer via Liaison <
> liaison_at_[hidden]> wrote:
>
> > I wonder if anyone has brought up the issue that for some standards,
> > member order are like parameter names in function declarations:
> > unspecified by the standard.
> >
>
> Ordering is part of the interface in C++, and users take advantage of
> that in subtle ways.
>
> The following code is well defined in C++:
>
> struct DrawArgs { int height, int width; };
> void draw(DrawArgs );
> //...
> int x = 0;
> draw({.height = ++x, .width = ++x});
>
> If the author of DrawArgs decided to reorder height and width, it
> would currently be a compile-time error in C++. If the ordering
> restriction is lifted, is this still well defined? Is it a silent
> breaking change for user code? And the hard question: how much real
> code would this silently break?
>
> This is not to say that WG21 won't lift the ordering constraint,
> rather, issues like the above need to be discussed as part of such a
> proposal.

IIRC, in C, initializer expressions within the same initializer are
unsequenced. So the above code would not have defined behavior in C.

Hm, that looks as if WG21 implemented a completely different feature
than WG14 :(

Since it seems that designated initializers are new in C++20, had that
particular property much been used before?

Jens

-- 
:: INRIA Nancy Grand Est ::: Camus ::::::: ICube/ICPS :::
:: ::::::::::::::: office Strasbourg : +33 368854536   ::
:: :::::::::::::::::::::: gsm France : +33 651400183   ::
:: ::::::::::::::: gsm international : +49 15737185122 ::
:: http://icube-icps.unistra.fr/index.php/Jens_Gustedt ::

Received on 2020-08-12 14:40:27