"exit 0;" - or - "exit (0);" ?
Kenneth R. Ballou
ballou at brahms
Tue Nov 18 06:54:31 AEST 1986
In article <1512 at batcomputer.tn.cornell.edu> braner at 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 at brahms.berkeley.edu
University of California
Berkeley, California 94720
More information about the Comp.lang.c
mailing list