C++ Logo

liaison

Advanced search

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

From: Jens Gustedt <jens.gustedt_at_[hidden]>
Date: Thu, 13 Aug 2020 10:46:59 +0200
Jens,

on Thu, 13 Aug 2020 10:12:09 +0200 you (Jens Maurer
<Jens.Maurer_at_[hidden]>) wrote:

> On 13/08/2020 09.42, Jens Gustedt wrote:
> > Ok, good to know. I will add something along the lines to my
> > document about the intersection of C and C++. It would go along the
> > lines
> >
> > C and C++ differ on an important aspect concerning
> > initializers. Where for C the expressions in an initializer
> > are unsequenced, C++ imposes specification of the initializers in
> > declaration order and sequences them according to that order.
> > As a consequence
> >
> > - providing designated initializers in an order that is
> > different from declaration order is a constraint violation
> > in C++,
> >
> > - in C, using expressions that must be sequenced to be valid
> > (such as multiple occurence of the same increment operation)
> > leads to undefined behavior.
> >
> > It is recommended that applications that target the common
> > C/C++ core list initializers in declaration order. Further it is
> > recommended that implementations that target that core
> > diagnose situations that would be problematic for the other
> > language, such as initializers not appearing in declaration order or
> > initializer expressions that require sequencing.
>
> I'd suggest to add cross-references to the respective standard's rule.
> For C++, this is [dcl.init.list] paragraph 4.

thanks, I'll note that in addition, but I have not yet done so for
similar notes, for the simple reason that I don't master the C++
standard well enough

> > I am not too optimistic we can change this situation, though. The
> > fact that initializer expressions and function argument evaluation
> > are unsequenced in C is deeply built into optimizers, I think.
>
> Note that C++ continues to have indeterminately sequenced
> (but NOT unsequenced) function call arguments; see C++ [expr.call]
> paragraph 8. The remaining freedom is necessary because some argument
> passing conventions might do left-to-right and others might do
> right-to-left. Requiring evaluation in left-to-right order may
> substantially pessimize some implementations.

Ok, right, so here we have another important difference. For C++ this
indeterminately sequenced whereas for C it is unsequenced. I'll add
that, too.

But maybe there is a pattern here? In C, operands of operators are
generally unsequenced, unless stated otherwise. The pattern suggests
that these are merely indeterminately sequenced for C++ ? If so, this
would merit a more general discussion in my document.

Thanks
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-13 03:50:27