Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c++ Subject: Re: two's complement idea Date: Mon, 27 Jan 2020 19:15:58 -0800 Organization: None to speak of Lines: 73 Message-ID: <874kwg46fl.fsf@nosuchdomain.example.com> References: <%JhXF.102988$%G5.101221@fx03.am4> <49pr2fphchn3dk2hiqv2bk8ml5oijs0d6e@4ax.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: reader02.eternal-september.org; posting-host="3b9d7e67aee25720b85e28e193eb2d8c"; logging-data="1786"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19hjk2IoQ7JYdUDzr0oO7nY" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) Cancel-Lock: sha1:qOUfiNQB1DNUmWdNInw96+kR18c= sha1:kvcG/JlH2Cx7eFgyog8bCvG+g4Y= Xref: csiph.com comp.lang.c++:71634 Robert Wessel writes: > On Mon, 27 Jan 2020 21:38:26 +0000, Bart wrote: [...] >>That makes it harder (would have taken longer than the 20 minutes I'd >>set aside). And it raises one issue: if this label is also a legal goto >>label, then: >> >> outerloop: >> for(;;) { while(1) { >> goto outerloop; >> break outerloop; >> }} >>// endofouterloop: >> >>the statements will jump to completely different points. The break >>actually goes to an implicit statement after the loop. > > > I think the slight oddity of target location when the label is used > for both a break/continue and a goto is pretty minor. I suppose we > could come up with some alternative way to specify a "statement name", > but I don't see a big advantage. If we can have a dozen meanings of > static, why not this. > >>At this point, it seems to me the following would actually be clearer: >> >> for(;;) { while(1) { >> goto endofouterloop; >> }} >> endofouterloop: >> >>as it pinpoints exactly where the code will end up next. With loads of >>nested }s floating around, many nothing to do with the loops, the end of >>the desired loop is not always easy to find. > > I think that's the wrong principle. If you want to target a specific > location, use a goto. The idea is to break/continue a loop/switch, so > it should be the *loop/switch* that should be identified. Personally, I like the way Ada does this. You can apply a label to a loop, and it's the name of the loop ("--" introduces a comment): OUTER: while condition loop INNER: while condition loop -- do stuff if Done_With_Outer then exit OUTER; -- "exit" is Ada for "break" elsif Done_With_Inner then exit INNER; end if; -- do more stuff end loop INNER; end loop OUTER; "exit OUTER" is best thought of as an operation that applies to the loop named "OUTER" rather than as a branch to a particular location. Loops that are the targets of goto statements have a different syntax, one that was designed to stand out: <