Date: Tue, 11 Aug 2020 21:05:31 +0000
Am Dienstag, den 11.08.2020, 17:01 -0400 schrieb Aaron Ballman:
> On Tue, Aug 11, 2020 at 4:45 PM Uecker, Martin
> <Martin.Uecker_at_[hidden]> wrote:
> >
> > Am Dienstag, den 11.08.2020, 16:41 -0400 schrieb Aaron Ballman:
> > > 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).
> >
> > I understand this. I was thinking more about a
> > high-level example where it would make sense to use
> > it in this way.
> >
> > A file which is opened and immediately close again
> > also does not make too much sense.
> >
> > But maybe there are better examples?
>
> My line of thinking may be contrived, but because constructors can
> accept arguments to them (including references or pointers to other
> objects), the RAII object could be performing some modification. e.g.,
>
> if (enable_special_magic)
> RAIIObject Special(Magic);
>
> where the constructor for RAIIObject takes an argument by reference
> and does something special to it (calls a function on it, modifies a
> value somewhere, etc). However, I wouldn't say this is a construct
> I've run across myself in the wild. As an example, perhaps the RAII
> object is logging to a file in the constructor (and perhaps flushing
> the file in the destructor).
>
> ~Aaron
Thanks Aaron!
I can see that it could potentially be used in some cases,
but it seems this was not added to the C++ language on purpose.
Best,
Martin
> >
> > Best,
> > Martin
> >
> >
> > > ~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_med.uni-goettingen.de
> > > > > > > <mailto:Martin.Uecker_at_med.uni-goettingen.de>> 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_lists.isocpp.org>> 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_lists.isocpp.org
> > > > Subscription: https://lists.isocpp.org/mailman/listinfo.cgi/liaison
> > > > Link to this post: http://lists.isocpp.org/liaison/2020/08/0115.php
> On Tue, Aug 11, 2020 at 4:45 PM Uecker, Martin
> <Martin.Uecker_at_[hidden]> wrote:
> >
> > Am Dienstag, den 11.08.2020, 16:41 -0400 schrieb Aaron Ballman:
> > > 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).
> >
> > I understand this. I was thinking more about a
> > high-level example where it would make sense to use
> > it in this way.
> >
> > A file which is opened and immediately close again
> > also does not make too much sense.
> >
> > But maybe there are better examples?
>
> My line of thinking may be contrived, but because constructors can
> accept arguments to them (including references or pointers to other
> objects), the RAII object could be performing some modification. e.g.,
>
> if (enable_special_magic)
> RAIIObject Special(Magic);
>
> where the constructor for RAIIObject takes an argument by reference
> and does something special to it (calls a function on it, modifies a
> value somewhere, etc). However, I wouldn't say this is a construct
> I've run across myself in the wild. As an example, perhaps the RAII
> object is logging to a file in the constructor (and perhaps flushing
> the file in the destructor).
>
> ~Aaron
Thanks Aaron!
I can see that it could potentially be used in some cases,
but it seems this was not added to the C++ language on purpose.
Best,
Martin
> >
> > Best,
> > Martin
> >
> >
> > > ~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_med.uni-goettingen.de
> > > > > > > <mailto:Martin.Uecker_at_med.uni-goettingen.de>> 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_lists.isocpp.org>> 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_lists.isocpp.org
> > > > 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 16:09:00