Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!decwrl!bacchus.pa.dec.com!decvax.dec.com!ima!esegue!compilers-sender From: thomasm@llama.ingres.com (Tom Markson) Newsgroups: comp.compilers Subject: Semicolons (Re: Low-Rent Syntax) Keywords: C, design, debug Message-ID: <9008202341.AA06543@llama.ingres.com> Date: 22 Aug 90 05:18:29 GMT Sender: compilers-sender@esegue.segue.boston.ma.us Reply-To: thomasm@llama.ingres.com (Tom Markson) Organization: Compilers Central Lines: 64 Approved: compilers@esegue.segue.boston.ma.us > Well, I'll admit it :-). I've been programming in C professionally for > about 5 years, and about 1/2 my extra trips into the editor are still to > correct missing semicolons. I almost never *add* semicolons, though. > This is true of most C programmers I know. And note that when the added > semicolon does appear, it usually takes the insidious form > x = 100; > while( x );/* a nasty case */ > /* > > * these comments are intended only to obscure the fact > * that the next statement will never be executed... > > */ > x--; The real problem here is not with the semicolon, it is with the grammar production that dominates C and Pascal: while: WHILE (expr) statement ; statement: '{' statements '}' | while ';' | /* etc */ ; Thus, If WHILE were terminated with ENDWHILE, This error would not occur: while: WHILE (expr) statements ';' ENDWHILE ';' ; statements: statements ';' statement | statement ; The semicolon in the erroneous code example above would simply be an empty statement. > I'm just plain tired of debugging code (of my own and others' :-) like > > if( v ) > w; > if( x ) > y; > else /*XXX*/; > z; Again, this is the same problem as above. As John mentioned, one safe way to do it in C is to ALWAYS use braces after an if,for, etc.. You'll find it makes your life much easier. -- Tom Markson Unix Systems email: thomasm@llama.rtech.com Ingres Corp phone: 415-748-250 -- Send compilers articles to compilers@esegue.segue.boston.ma.us {ima | spdcc | world}!esegue. Meta-mail to compilers-request@esegue.