C++ Logo


Advanced search

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

From: Nevin Liber <nevin_at_[hidden]>
Date: Wed, 12 Aug 2020 14:07:30 -0500
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

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.
 Nevin ":-)" Liber  <mailto:nevin_at_[hidden] <nevin_at_[hidden]>>

Received on 2020-08-12 14:11:30