Algol-style vs C-style semicolons - (nf)

#M.CONDICT mnc at hou2g.UUCP
Sat Jun 9 02:52:48 AEST 1984


Not wishing to drag out a rather uninteresting discussion but unable to
resist pontificating on language design matters, I submit the following
on the semicolon controversy.  It is true that semicolons are not, strictly
speaking, statement terminators in C, because not all statements end with
them.  In fact, a quick look at the grammar in the C Reference Manual shows
that only the following statements are terminated with semicolons:

	expression ;
	do statement while ( expression ) ;  /* This one was new to me! */
	return expr ;
	goto identifier ;
	continue ;
	break ;
	;			/* A null statement */

The rest, including for loops, while loops and compound statements are not.
It is the presence of null statements that confuses the matter by making
people think that

	while ( expr ) statement ;

is one statement and is terminated with a semicolon, when in fact it is
two statements -- a while loop followed by a null statement.

Can anyone explain why, of all the loop statements, only do-while is
terminated with semicolon?  The required closing right-paren would seem
sufficient for easy parsing.

Michael Condict    allegra!hou2g!mnc
AT&T Bell Labs,
Holmdel



More information about the Comp.lang.c mailing list