new do-while syntax

Sean Fagan seanf at sco.COM
Thu Dec 22 12:30:58 AEST 1988


In article <1716 at buengc.BU.EDU> bph at buengc.bu.edu (Blair P. Houghton) writes:
>In article <864 at calvin.EE.CORNELL.EDU> johns at calvin.ee.cornell.edu.UUCP (John Sahr) writes:
>>>In article <8536 at alice.UUCP>, ark at alice.UUCP (Andrew Koenig) writes:
>But what's wrong with [the following code]?
]	do {
]		process(ch);
]		process2(ch);
]		process3(ch);
]	} while (
]		ch = getchar(),
]		ch &= MASK,
]		ch  = table_look_up[ch],
]		report_status(ch),
]		ch != EOF
]	);

Uhm, little thinks like the fact that quite a few compilers will generate
the equivalent of:
	do {
		proces(ch);
		process2(ch);
		process3(ch);
	} while (
		getchar(), ch&MASK, table_look_op[ch], report_status(ch),
		ch != EOF)
	;

which is all that you're guarenteed (assuming the compiler does no
optimizations).  Put some optimizations in (assuming ch is non-volatile in
a dpANSI compiler, or the compiler assumes it isn't), and you get:

	getchar(), report_status(ch), ch!=EOF

as the conditional for the while.

Also, ch is not initialized to the getchar(), which it was in the initial
example (which I deleted, of course), and the code looks horrible.

Is that enough?

-- 
Sean Eric Fagan  | "Merry Christmas, drive carefully and have some great sex."
seanf at sco.UUCP   |     -- Art Hoppe
(408) 458-1422   | Any opinions expressed are my own, not my employers'.



More information about the Comp.lang.c mailing list