C++ Logo

liaison

Advanced search

Re: [wg14/wg21 liaison] labels

From: Aaron Ballman <aaron_at_[hidden]>
Date: Tue, 11 Aug 2020 16:41:07 -0400
On Tue, Aug 11, 2020 at 4:38 PM Uecker, Martin via Liaison
<liaison_at_[hidden]> wrote:
>
>
> BTW: Is
>
> if (x)
> int y;
>
> intentionally allowed in C++? Is there a sensible use
> case?

Yes, that's well-formed C++ code. A possible use case would be for an
RAII object which performs work in its constructor or destructor (so
the declaration itself causes code to be executed).

~Aaron

>
> Best,
> Martin
>
> Am Dienstag, den 11.08.2020, 22:11 +0200 schrieb Martin Uecker:
> >
> > Am Dienstag, den 11.08.2020, 21:31 +0200 schrieb Bjarne Stroustrup:
> > > What benefits was this supposed to give programmers?
> >
> > It actually saves me time when writing C, because currently
> > have to recompile sometimes just to add a pointless
> > null statements. It is one of the main annoyances
> > when writing C.
> >
> > It is also difficult to explain to students
> > why you can not place a label before a declaration or
> > at the end of a block while it makes perfect sense
> > to jump there.
> >
> > C++ allows placing labels in front of declarations,
> > so the also improves compatibility.
> >
> > > Was the benefits worth the change to almost 50 years practice and
> > > documentation worth it?
> >
> > There is hardly anything to change, as it is entirely
> > backward compatible and simply removes an annoying
> > corner case from the language.
> >
> > > Are the old corner cases worse than the new ones?
> >
> > In C, there a no corner case anymore. You can place a label
> > everywhere you could place a statement.
> >
> >
> > Best,
> > Martin
> >
> >
> > > On 8/11/2020 6:43 PM, Richard Smith via Liaison wrote:
> > > > On Tue, 11 Aug 2020, 09:16 Uecker, Martin,
> > > > <Martin.Uecker_at_[hidden]
> > > > <mailto:Martin.Uecker_at_[hidden]>> wrote:
> > > >
> > > > Am Dienstag, den 11.08.2020, 09:04 -0700 schrieb Richard Smith:
> > > > > On Mon, 10 Aug 2020, 23:37 Uecker, Martin via Liaison, <
> > > > > liaison_at_[hidden] <mailto:liaison_at_[hidden]>> wrote:
> > > > >
> > > > > >
> > > > > > Hi all,
> > > > > >
> > > > > > I recently proposed changes to the C grammar which got
> > > > > > voted into C2X by WG14 (N2508, also see N2496).
> > > > > >
> > > > > > This allows placing of labels everywhere in a compound
> > > > > > statement, even before declarations and at the end
> > > > > > of a block, which was not possible in C so far.
> > > > > >
> > > > > > Example:
> > > > > >
> > > > > > {
> > > > > > start:
> > > > > > int i;
> > > > > > mid:
> > > > > > int j;
> > > > > > end:
> > > > > > }
> > > > > >
> _______________________________________________
> 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/0115.php

Received on 2020-08-11 15:44:46