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 16:30 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <o0klua$oqi$1@dont-email.me> (permalink) |
| References | (4 earlier) <o09n7h$c0i$1@dont-email.me> <ec02f6d7-55e4-421f-9873-9e1128b534a9@googlegroups.com> <o0a2o7$j0o$3@dont-email.me> <e93fdmFn7n5U1@mid.individual.net> <o0kdqf$pv3$2@dont-email.me> |
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
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