Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | BartC <bc@freeuk.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Minimum amount of syntax for C language |
| Date | 2016-11-17 19:10 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <o0kvad$tk4$1@dont-email.me> (permalink) |
| References | (5 earlier) <ec02f6d7-55e4-421f-9873-9e1128b534a9@googlegroups.com> <o0a2o7$j0o$3@dont-email.me> <e93fdmFn7n5U1@mid.individual.net> <6963fc34-48b1-490f-b404-7ff4975b7780@googlegroups.com> <o0kuk1$pbn$1@jstuckle.eternal-september.org> |
On 17/11/2016 18:58, Jerry Stuckle wrote:
> On 11/17/2016 12:03 PM, John Bode wrote:
>> On Wednesday, November 16, 2016 at 10:22:23 AM UTC-6, Osmium wrote:
>>> "Mr. Man-wai Chang" wrote:
>>>
>>>> For teaching purposes, do you need complete and full C syntax? DO you need
>>>> a sophiscated compiler?
>>>
>>> On further thought, I can't think of any situation where the goto
>>> statement is required.
>>
>> Not *required*, but one place where it is useful (and not immediately a
>> sign of poor design or practice) is bailing out of a deeply nested loop
>> or multi-step resource allocation process:
>>
>> for ( ... )
>> for ( ... )
>> for ( ... )
>> if ( some_error )
>> goto exit:
>>
>> exit: // clean up
>>
>> Obviously, you'll want to structure your code such that you avoid that
>> situation, but sometimes it simply isn't possible (or, the level of
>> effort required to do so is not worth the tradeoff).
>>
>
> Or,
>
> bool exit = false;
> for (... && !exit)
> for (... && !exit)
> for (... && !exit)
> if (some_error) {
> exit = true;
> break;
> }
>
> Clean easy to understand and no goto.
But it won't do the same thing. Suppose there is extra code after each loop:
for ( ... ) {
for ( ... ) {
for ( ... ) {
if ( some_error )
goto exit:
}
A;
}
B;
}
C;
// clean up ...
With your scheme, A and B will still be executed before it quits the
outer loop, and C will be executed on exit from the outer loop.
Apart from which you don't your code cluttered up with all this extra logic.
--
Bartc
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Minimum amount of syntax for C language "Mr. Man-wai Chang" <toylet.toylet@gmail.com> - 2016-11-13 18:56 +0800
Re: Minimum amount of syntax for C language BartC <bc@freeuk.com> - 2016-11-13 11:26 +0000
[OT] "Mr. Man-wai Chang" <toylet.toylet@gmail.com> - 2016-11-13 19:41 +0800
Re: [OT] BartC <bc@freeuk.com> - 2016-11-13 12:42 +0000
Minimum amount of syntax for C language "Mr. Man-wai Chang" <toylet.toylet@gmail.com> - 2016-11-13 20:45 +0800
Re: Minimum amount of syntax for C language jameskuyper@verizon.net - 2016-11-13 07:42 -0800
Re: Minimum amount of syntax for C language "Mr. Man-wai Chang" <toylet.toylet@gmail.com> - 2016-11-14 00:01 +0800
Re: Minimum amount of syntax for C language jameskuyper@verizon.net - 2016-11-13 10:00 -0800
Re: Minimum amount of syntax for C language "Osmium" <r124c4u102@comcast.net> - 2016-11-13 13:16 -0600
Re: Minimum amount of syntax for C language BartC <bc@freeuk.com> - 2016-11-13 19:28 +0000
Re: Minimum amount of syntax for C language Thiago Adams <thiago.adams@gmail.com> - 2016-11-14 08:10 -0800
Re: Minimum amount of syntax for C language John Bode <jfbode1029@gmail.com> - 2016-11-14 12:34 -0800
Re: Minimum amount of syntax for C language "Osmium" <r124c4u102@comcast.net> - 2016-11-16 10:22 -0600
Re: Minimum amount of syntax for C language supercat@casperkitty.com - 2016-11-16 08:33 -0800
Re: Minimum amount of syntax for C language "Mr. Man-wai Chang" <toylet.toylet@gmail.com> - 2016-11-17 22:11 +0800
Re: Minimum amount of syntax for C language BartC <bc@freeuk.com> - 2016-11-17 16:30 +0000
Re: Minimum amount of syntax for C language "Mr. Man-wai Chang" <toylet.toylet@gmail.com> - 2016-11-18 01:05 +0800
Re: Minimum amount of syntax for C language John Bode <jfbode1029@gmail.com> - 2016-11-17 09:03 -0800
Re: Minimum amount of syntax for C language Jerry Stuckle <jstucklex@attglobal.net> - 2016-11-17 13:58 -0500
Re: Minimum amount of syntax for C language BartC <bc@freeuk.com> - 2016-11-17 19:10 +0000
Re: Minimum amount of syntax for C language Jerry Stuckle <jstucklex@attglobal.net> - 2016-11-17 17:41 -0500
Re: Minimum amount of syntax for C language Thiago Adams <thiago.adams@gmail.com> - 2016-11-17 11:03 -0800
Re: Minimum amount of syntax for C language Keith Thompson <kst-u@mib.org> - 2016-11-17 11:56 -0800
Re: Minimum amount of syntax for C language "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-11-17 12:17 -0800
Re: Minimum amount of syntax for C language Thiago Adams <thiago.adams@gmail.com> - 2016-11-17 12:21 -0800
csiph-web