Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rutgers!sri-unix!hplabs!ucbvax!cartan!brahms!ballou From: ballou@brahms (Kenneth R. Ballou) Newsgroups: comp.lang.c Subject: Re: "exit 0;" - or - "exit (0);" ? Message-ID: <331@cartan.Berkeley.EDU> Date: Mon, 17-Nov-86 15:54:31 EST Article-I.D.: cartan.331 Posted: Mon Nov 17 15:54:31 1986 Date-Received: Mon, 17-Nov-86 22:24:14 EST References: <1512@batcomputer.tn.cornell.edu> Sender: daemon@cartan.Berkeley.EDU Reply-To: ballou@brahms (Kenneth R. Ballou) Distribution: net Organization: Math Dept. UC Berkeley Lines: 45 In article <1512@batcomputer.tn.cornell.edu> braner@batcomputer.UUCP (braner) writes: >While K&R explicitly say that exit() is a function, I commonly see >the parens dropped. Is that "legal"? Does it work on existing compilers? Note that 'exit' is not a reserved word in (K&R) C. Therefore, the compiler should reject the construct exit 0; on at least two grounds. If you have not previously declared exit to be a function, it should complain that exit is an undefined variable. Then it should complain because you have two rvalues with no operator in between. >And while I am asking: how's "if (foo) {...}" vs. "if foo {...}" ? >(in the case where "foo" is a variable, say an int used as a flag.) Perhaps I should be charitable and assume that you simply do not have access to either K&R or Harbison and Steele to look this up yourself, although I find it hard to believe that Cornell does not have libraries. K&R, page 201: Near the bottom of the page we see 9.3 Conditional statement The two forms of the conditional statement are if ( expression ) statement if ( expression ) statement else statement Harbison and Steele, page 202: In the section titled "Conditional Statement," we have: conditional-statement ::= if-statement | if-else-statement if-statement ::= if '(' expression ')' statement if-else-statement ::= if '(' expression ')' statement else statement This very same information can be found on page 331 of H&S in the last three lines. For a more rigorous description, you might turn to page 339 in Appendix C, "LALR(1) grammar for C". I think I have made my point. People have written books which specify the grammar of C. I sometimes wonder why they go through all the bother ... -------- Kenneth R. Ballou ...!ucbvax!brahms!ballou Department of Mathematics ballou@brahms.berkeley.edu University of California Berkeley, California 94720