Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #96466 > unrolled thread
| Started by | "Mr. Man-wai Chang" <toylet.toylet@gmail.com> |
|---|---|
| First post | 2016-11-13 18:56 +0800 |
| Last post | 2016-11-17 12:21 -0800 |
| Articles | 20 on this page of 25 — 10 participants |
Back to article view | Back to comp.lang.c
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
Page 1 of 2 [1] 2 Next page →
| From | "Mr. Man-wai Chang" <toylet.toylet@gmail.com> |
|---|---|
| Date | 2016-11-13 18:56 +0800 |
| Subject | Minimum amount of syntax for C language |
| Message-ID | <o09gs8$kuu$11@dont-email.me> |
Have it ever been discussed before? :)
[toc] | [next] | [standalone]
| From | BartC <bc@freeuk.com> |
|---|---|
| Date | 2016-11-13 11:26 +0000 |
| Message-ID | <o09ikt$srt$2@dont-email.me> |
| In reply to | #96466 |
On 13/11/2016 10:56, Mr. Man-wai Chang wrote: > > Have it ever been discussed before? :) Are you a bot?
[toc] | [prev] | [next] | [standalone]
| From | "Mr. Man-wai Chang" <toylet.toylet@gmail.com> |
|---|---|
| Date | 2016-11-13 19:41 +0800 |
| Subject | [OT] |
| Message-ID | <o09jfs$uoc$4@dont-email.me> |
| In reply to | #96467 |
On 13/11/2016 7:26 PM, BartC wrote: > > Are you a bot? You are NOT answering the question.
[toc] | [prev] | [next] | [standalone]
| From | BartC <bc@freeuk.com> |
|---|---|
| Date | 2016-11-13 12:42 +0000 |
| Subject | Re: [OT] |
| Message-ID | <o09n3i$b25$1@dont-email.me> |
| In reply to | #96470 |
On 13/11/2016 11:41, Mr. Man-wai Chang wrote: > On 13/11/2016 7:26 PM, BartC wrote: >> >> Are you a bot? > > You are NOT answering the question. The answer is YES then. Unless you can make at least one post that will convince me otherwise.
[toc] | [prev] | [next] | [standalone]
| From | "Mr. Man-wai Chang" <toylet.toylet@gmail.com> |
|---|---|
| Date | 2016-11-13 20:45 +0800 |
| Message-ID | <o09n7h$c0i$1@dont-email.me> |
| In reply to | #96477 |
On 13/11/2016 8:42 PM, BartC wrote: > > The answer is YES then. Unless you can make at least one post that will > convince me otherwise. The question was and is: Minimum amount of syntax for C language Have it ever been discussed before?
[toc] | [prev] | [next] | [standalone]
| From | jameskuyper@verizon.net |
|---|---|
| Date | 2016-11-13 07:42 -0800 |
| Message-ID | <ec02f6d7-55e4-421f-9873-9e1128b534a9@googlegroups.com> |
| In reply to | #96478 |
On Sunday, November 13, 2016 at 7:45:10 AM UTC-5, Mr. Man-wai Chang wrote:
> On 13/11/2016 8:42 PM, BartC wrote:
> >
> > The answer is YES then. Unless you can make at least one post that will
> > convince me otherwise.
>
> The question was and is:
>
> Minimum amount of syntax for C language
>
> Have it ever been discussed before?
BartC's point is that only a bot would bother posting such a vague and
meaningless question. I think he's over-estimating humans - I think it's
entirely possible that you are a human who makes a habit of posting vague and
meaningless questions.
If you want to find out if it's been discussed before, do a Google Groups
search. A vague unfocused topic like yours is going to be very difficult to
search for, which is why it would be better for you to do the hard work of
searching for such a discussion.
Now, it's possible that you've asked the wrong question, as that seems to be a
habit of yours. Assuming that BartC is wrong, that you are not a bot, then I
suspect your real question isn't whether this topic has been discussed before.
I suspect that there's something specific you want to know about the minimal
syntax for C. If so, you should ask about that specific thing. If and when you
do so, there's certain additional things you need to do:
1. Define what measure of the syntax you want to minimize.
2. Define the range of possible syntaxes that you want to minimize over. For
any given version of C, the syntax is describe by two official grammars, the
lexical grammar and the phrase structure grammar, which are summarized in Annex
A. In addition, many of C's constraints are syntactic rather than semantic:
they could have been expressed as grammar rules rather than as constraints, at
the cost of making the grammar far more complex. Given syntax rules defined in
that manner, how would you determine if one syntax is more minimal than another?
The standard's summary of that grammar in Annex A is complete and has very
little in the way of wasted words - if it isn't precisely the smallest complete
grammar that could be used to define the language, it probably comes close. Of
all the standard grammars for C, the one that's smallest was probably the one
for the oldest version of C, since each version added many more new features
than it removed. Is that what you're looking for?
Are you thinking about minimize over a range of simplified versions of C? Would
a grammar that has been simplified so far that the only program that it can
actually describe is "int main() {}" be acceptable? If so, that grammar is
probably the minimal one that could, by an extreme stretch of the imagination,
be described as a simplified C grammar. If that's too simplified, then you need
to specify constraints on how far the simplification may go.
3. Explain why you're interested in this minimum syntax. I think one of the key
reasons BartC is accusing you of being a bot is he can't imagine why a human
would care about this topic, and I have to agree. If you do care, explain why.
[toc] | [prev] | [next] | [standalone]
| From | "Mr. Man-wai Chang" <toylet.toylet@gmail.com> |
|---|---|
| Date | 2016-11-14 00:01 +0800 |
| Message-ID | <o0a2o7$j0o$3@dont-email.me> |
| In reply to | #96491 |
On 13/11/2016 11:42 PM, jameskuyper@verizon.net wrote:
>
> 1. Define what measure of the syntax you want to minimize.
>
> 2. Define the range of possible syntaxes that you want to minimize over. For
> any given version of C, the syntax is describe by two official grammars, the
> lexical grammar and the phrase structure grammar, which are summarized in Annex
> A. In addition, many of C's constraints are syntactic rather than semantic:
> they could have been expressed as grammar rules rather than as constraints, at
> the cost of making the grammar far more complex. Given syntax rules defined in
> that manner, how would you determine if one syntax is more minimal than another?
>
> The standard's summary of that grammar in Annex A is complete and has very
> little in the way of wasted words - if it isn't precisely the smallest complete
> grammar that could be used to define the language, it probably comes close. Of
> all the standard grammars for C, the one that's smallest was probably the one
> for the oldest version of C, since each version added many more new features
> than it removed. Is that what you're looking for?
>
> Are you thinking about minimize over a range of simplified versions of C? Would
> a grammar that has been simplified so far that the only program that it can
> actually describe is "int main() {}" be acceptable? If so, that grammar is
> probably the minimal one that could, by an extreme stretch of the imagination,
> be described as a simplified C grammar. If that's too simplified, then you need
> to specify constraints on how far the simplification may go.
>
> 3. Explain why you're interested in this minimum syntax. I think one of the key
> reasons BartC is accusing you of being a bot is he can't imagine why a human
> would care about this topic, and I have to agree. If you do care, explain why.
>
For teaching purposes, do you need complete and full C syntax? DO you
need a sophiscated compiler?
You might be right, I might have asked the wrong question because of my
poor English ability and fluency. :)
[toc] | [prev] | [next] | [standalone]
| From | jameskuyper@verizon.net |
|---|---|
| Date | 2016-11-13 10:00 -0800 |
| Message-ID | <5b9fa641-3924-4316-99b7-9be6f092f307@googlegroups.com> |
| In reply to | #96492 |
On Sunday, November 13, 2016 at 11:01:49 AM UTC-5, Mr. Man-wai Chang wrote: ... > For teaching purposes, do you need complete and full C syntax? DO you > need a sophiscated compiler? At any given time during the process of teaching someone to use C, they will have learned only part of the syntax, but that part is constantly growing during their education, which I cannot consider to be complete until they've been at least exposed to all of the features of the language. I don't think that there's any particular "minimal syntax" that should be targeted, just a constantly expanding subset of the full language. For teaching standard C, you need a compiler that has a mode that fully conforms to at least one version of the C standard, which includes correctly recognizing all C syntax. Anything else might lead to the students learning to use C incorrectly. The more sophisticated the compiler is at detecting problems in the code, the better, especially for students. The only kind of sophistication that isn't strictly necessary is high quality optimizations (which I'm sure will please supercat no end). > You might be right, I might have asked the wrong question because of my > poor English ability and fluency. :) I don't think so. I've a lot of experience dealing with people who's native language is not English, including my wife, her family, and many of my co-workers. Many of them speak Mandarin (is that your native language?). When I look at what you've written, I don't see anything in most of your posts that could plausibly be a poorly translated but meaningful question. I just see a lot of vague and meaningless questions. The problem lies in what you choose to ask, not in how you translate your questions once you've chosen them.
[toc] | [prev] | [next] | [standalone]
| From | "Osmium" <r124c4u102@comcast.net> |
|---|---|
| Date | 2016-11-13 13:16 -0600 |
| Message-ID | <e8rsgsFst7vU1@mid.individual.net> |
| In reply to | #96492 |
"Mr. Man-wai Chang" wrote: > For teaching purposes, do you need complete and full C syntax? DO you need > a sophiscated compiler? I would say yes, you need all the syntax. But there are different versions of C. The so-called ANSI C, the first one that had an international standard, is perfectly adequate. So you wouldn't get any aid to do complex numbers, for example. There is a wonderful text, by Kernighan and Ritchie that describes that version. Sophisticated is a subjective word but I would say no, the compiler need not be sophisticated, C is a kind of run of the mill, procedure-oriented language.
[toc] | [prev] | [next] | [standalone]
| From | BartC <bc@freeuk.com> |
|---|---|
| Date | 2016-11-13 19:28 +0000 |
| Message-ID | <o0aes0$qgv$1@dont-email.me> |
| In reply to | #96503 |
On 13/11/2016 19:16, Osmium wrote: > "Mr. Man-wai Chang" wrote: > >> For teaching purposes, do you need complete and full C syntax? DO you >> need a sophiscated compiler? > > Sophisticated is a > subjective word but I would say no, the compiler need not be > sophisticated, C is a kind of run of the mill, procedure-oriented language. The first obstacle is that you need to write a preprocessor before you can start compiling proper. So it's really two languages. The unusual number of quirks can also be a factor. Example: it's a little bit harder to allow: int a,a,a,(a),a,((a)),a; than not to allow it. [Because you have to check that each 'a' is in the right scope to allow multiple declarations, that all declaration share a compatible type, and that at most one 'a' is initialised. As opposed to just bailing out at the second 'a'.] -- Bartc
[toc] | [prev] | [next] | [standalone]
| From | Thiago Adams <thiago.adams@gmail.com> |
|---|---|
| Date | 2016-11-14 08:10 -0800 |
| Message-ID | <285dc556-d7ca-4ce9-a9f2-096540f55a45@googlegroups.com> |
| In reply to | #96504 |
On Sunday, November 13, 2016 at 5:28:46 PM UTC-2, Bart wrote:
> On 13/11/2016 19:16, Osmium wrote:
> > "Mr. Man-wai Chang" wrote:
> >
> >> For teaching purposes, do you need complete and full C syntax? DO you
> >> need a sophiscated compiler?
> >
>
> > Sophisticated is a
> > subjective word but I would say no, the compiler need not be
> > sophisticated, C is a kind of run of the mill, procedure-oriented language.
>
> The first obstacle is that you need to write a preprocessor before you
> can start compiling proper. So it's really two languages.
>
> The unusual number of quirks can also be a factor. Example: it's a
> little bit harder to allow:
>
> int a,a,a,(a),a,((a)),a;
>
> than not to allow it.
>
> [Because you have to check that each 'a' is in the right scope to allow
> multiple declarations, that all declaration share a compatible type, and
> that at most one 'a' is initialised. As opposed to just bailing out at
> the second 'a'.]
I haven´t implemented this, but I think after normal declarator check, this one will be the same. It´s just ugly, but the compiler doesn't care.
This is also something different from local and global.
What I think should me simplified at the begging of the C language is the syntax of structs/union/enums in C.
I think the syntax for structs/unions/enum should be:
struct { int i; }; //useless like int;
struct { int i; } x; //fine
typedef struct { int i; } X; //fine
struct X x; // should be non-sense
The only case where it would make sense is forward declaration
typedef struct X;
typedef struct { X* pNext; } X;
The way it was created:
struct X
{
int i;
};
it´s a kind of hidden typedef, but at the same time it´s not a typedef.
[toc] | [prev] | [next] | [standalone]
| From | John Bode <jfbode1029@gmail.com> |
|---|---|
| Date | 2016-11-14 12:34 -0800 |
| Message-ID | <c6072193-f12e-460d-a765-76a63331e73d@googlegroups.com> |
| In reply to | #96492 |
On Sunday, November 13, 2016 at 10:01:49 AM UTC-6, Mr. Man-wai Chang wrote: [snippity] > For teaching purposes, do you need complete and full C syntax? No, you don't need to *teach* every single aspect of the syntax from translation-unit on down, although by the time you've finished an intro class you will have covered most of it. > DO you need a sophiscated compiler? Define "sophisticated". You don't need a full-up IDE in the manner of Visual Studio or Eclipse, but it's not like gcc (or MinGW) is going to tax any system that any modern student would be using.
[toc] | [prev] | [next] | [standalone]
| From | "Osmium" <r124c4u102@comcast.net> |
|---|---|
| Date | 2016-11-16 10:22 -0600 |
| Message-ID | <e93fdmFn7n5U1@mid.individual.net> |
| In reply to | #96492 |
"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.
[toc] | [prev] | [next] | [standalone]
| From | supercat@casperkitty.com |
|---|---|
| Date | 2016-11-16 08:33 -0800 |
| Message-ID | <46990378-41e4-4866-9c59-2ebe70824e23@googlegroups.com> |
| In reply to | #96692 |
On Wednesday, November 16, 2016 at 10:22:23 AM UTC-6, Osmium wrote: > On further thought, I can't think of any situation where the goto statement > is required. One obvious situation would be reading any existing code in which it is used. A second situation is when writing a code generator for constructs which, from the code generator's perspective, are unstructured. For example, if one were writing a program to translate an HP-2000 BASIC program into C, it would be much easier to have the generated C code use "goto" in the same fashion as the BASIC source than to try to restructure the program. Finally, even when a person is writing code for business rules which don't fit normal code structures, it's often better to use gotos than to try to fake them via other means. One could replace all control structures with a single "while(live)" loop that surrounds a single "switch" statement, but switch/case is really nothing but a goto in disguise.
[toc] | [prev] | [next] | [standalone]
| From | "Mr. Man-wai Chang" <toylet.toylet@gmail.com> |
|---|---|
| Date | 2016-11-17 22:11 +0800 |
| Message-ID | <o0kdqf$pv3$2@dont-email.me> |
| In reply to | #96692 |
On 17/11/2016 12:22 AM, 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. From my programming experiences in the business world using Foxpro, there is really no need for GOTO, *except* in ERROR HANDLING! The original C language does NOT have exception handling.
[toc] | [prev] | [next] | [standalone]
| From | BartC <bc@freeuk.com> |
|---|---|
| Date | 2016-11-17 16:30 +0000 |
| Message-ID | <o0klua$oqi$1@dont-email.me> |
| In reply to | #96731 |
On 17/11/2016 14:11, Mr. Man-wai Chang wrote:
> On 17/11/2016 12:22 AM, 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.
>
> From my programming experiences in the business world using Foxpro,
> there is really no need for GOTO, *except* in ERROR HANDLING! The
> original C language does NOT have exception handling.
If someone wants to generate unstructured, intermediate code like the
following, which other high level language /with optimising compilers/
could be used if C didn't have 'goto'?
-----------------------------------------------
void testlist(node (*nos)[1],i32 n,i32 target) {
i32 i;
i32 j;
i32 k;
i32 m;
i32 i2;
i32 j2;
i32 a;
i32 b;
i32 value;
i32 opc;
node newnos[6];
i32 av$2;
node (*$1);
i32 $2;
i32 $3;
node $4;
node (*$5);
node (*$6);
i32 $7;
i32 $8;
i32 $9;
i32 $10;
node (*$11);
node (*$12);
node (*$13);
node (*$14);
node (*$15);
node (*$16);
if (!done) goto L13;
return;
L13:
++attempts;
L14:
i = 1;
if (n < 1) goto L17;
L15:
$1 = ((node*)nos+i-1);
if (*((i32*)$1) != target) goto L18;
++solutions;
if (solutions != 1000000) goto L19;
done = 1;
return;
L19:
L18:
L16:
++i;
if (i <= n) goto L15;
L17:
if (n != 1) goto L20;
return;
L20:
L21:
i = 1;
$2 = n-1;
if ($2 < 1) goto L24;
L22:
L25:
$3 = i+1;
j = $3;
if (j > n) goto L28;
L26:
m = 0;
L29:
k = 1;
if (n < 1) goto L32;
L30:
if (k == i) goto L33;
if (k == j) goto L33;
m += 1;
$4 = *((node*)nos+k-1);
*(newnos+m-1) = $4;
L33:
L31:
++k;
if (k <= n) goto L30;
L32:
m += 1;
i2 = i;
j2 = j;
$5 = ((node*)nos+i2-1);
a = *((i32*)$5);
$6 = ((node*)nos+j2-1);
b = *((i32*)$6);
L34:
opc = 1;
L35:
switch (opc) {;
case 1:
if (a == 0) goto L40;
if (b != 0) goto L39;
L40:
++rejects;
goto L41;
L39:
value = a+b;
break;
case 2:
$7 = a|b;
if ($7 != 0) goto L42;
++rejects;
goto L41;
L42:
value = a-b;
break;
case 3:
if (a <= 1) goto L44;
if (b > 1) goto L43;
L44:
++rejects;
goto L41;
L43:
value = a*b;
break;
case 4:
if (b > 1) goto L45;
++rejects;
goto L41;
L45:
value = a/b;
$8 = a%b;
if ($8 == 0) goto L46;
++rejects;
goto L41;
L46:
break;
case 5:
i2 = j;
j2 = i;
$9 = a|b;
if ($9 != 0) goto L47;
++rejects;
goto L41;
L47:
value = b-a;
break;
case 6:
i2 = j;
j2 = i;
if (a > 1) goto L48;
++rejects;
goto L41;
L48:
value = b/a;
$10 = b%a;
if ($10 == 0) goto L49;
++rejects;
goto L41;
L49:
break;
};
L38:
$11 = (newnos+m-1);
*(i32 (*))((byte*)$11) = value;
$12 = (newnos+m-1);
*(i32 (*))((byte*)$12+4) = opc;
$13 = (newnos+m-1);
$14 = ((node*)nos+i2-1);
*(node (*(*)))((byte*)$13+8) = $14;
$15 = (newnos+m-1);
$16 = ((node*)nos+j2-1);
*(node (*(*)))((byte*)$15+12) = $16;
level += 1;
testlist((node (*)[1])newnos,m,target);
level -= 1;
L41:
L36:
++opc;
if (opc <= 6) goto L35;
L37:
L27:
++j;
if (j <= n) goto L26;
L28:
L23:
++i;
if (i <= $2) goto L22;
L24:
L12:
;
} /*testlist*/
(
-- (i32 means int32_t
-- $, used for temporary variables, is not valid in identifiers with
some C compilers, but is more visible than _
-- 'node' is a typedef for a struct but I believe it's treated here
as an opaque block of bytes
)
--
Bartc
[toc] | [prev] | [next] | [standalone]
| From | "Mr. Man-wai Chang" <toylet.toylet@gmail.com> |
|---|---|
| Date | 2016-11-18 01:05 +0800 |
| Message-ID | <o0knvu$u7l$6@dont-email.me> |
| In reply to | #96744 |
On 18/11/2016 12:30 AM, BartC wrote:
> On 17/11/2016 14:11, Mr. Man-wai Chang wrote:
>> On 17/11/2016 12:22 AM, Osmium wrote:
>>
>> From my programming experiences in the business world using Foxpro,
>> there is really no need for GOTO, *except* in ERROR HANDLING! The
>> original C language does NOT have exception handling.
>
> If someone wants to generate unstructured, intermediate code like the
> following, which other high level language /with optimising compilers/
> could be used if C didn't have 'goto'?
>
> -----------------------------------------------
>
> void testlist(node (*nos)[1],i32 n,i32 target) {
> i32 i;
> ....
Master, I think you replied the wrong thread. Maybe you people should
start learning to use new thread when an old one runs too long too many
in a limited screen.
[toc] | [prev] | [next] | [standalone]
| From | John Bode <jfbode1029@gmail.com> |
|---|---|
| Date | 2016-11-17 09:03 -0800 |
| Message-ID | <6963fc34-48b1-490f-b404-7ff4975b7780@googlegroups.com> |
| In reply to | #96692 |
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).
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2016-11-17 13:58 -0500 |
| Message-ID | <o0kuk1$pbn$1@jstuckle.eternal-september.org> |
| In reply to | #96751 |
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.
--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================
[toc] | [prev] | [next] | [standalone]
| From | BartC <bc@freeuk.com> |
|---|---|
| Date | 2016-11-17 19:10 +0000 |
| Message-ID | <o0kvad$tk4$1@dont-email.me> |
| In reply to | #96760 |
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
[toc] | [prev] | [next] | [standalone]
Page 1 of 2 [1] 2 Next page →
Back to top | Article view | comp.lang.c
csiph-web