Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rutgers!mit-eddie!genrad!decvax!ucbvax!ucdavis!nagel@iris.ucdavis.edu (Mark Nagel) From: nagel@iris.ucdavis.edu (Mark Nagel) Newsgroups: comp.lang.c Subject: Re: COMMA separated expresses Message-ID: <595@ucdavis.UUCP> Date: Thu, 25-Jun-87 12:38:27 EDT Article-I.D.: ucdavis.595 Posted: Thu Jun 25 12:38:27 1987 Date-Received: Sat, 27-Jun-87 02:28:36 EDT References: <1601@oliveb.UUCP> Sender: uucp@ucdavis.UUCP Reply-To: nagel@iris.UUCP (Mark Nagel) Distribution: world Organization: University of California, Davis Lines: 37 In article <1601@oliveb.UUCP> dchen@oliveb.UUCP (Dennis T. Chen) writes: >Why did my C compiler(came with 4.3bsd) complaint the "syntax error" >with the following COMMA separated express statements in a function: > >funct() >{ > int i = 0; > > if ( i == 0 ) > printf("A\n"), return; /* syntax error here */ > printf("END\n"); >} > >But it works fine with > > if ( i == 0 ) > printf("A\n"), exit(1); /* compile OK */ > >Could someone point this out ? It seems to me that rule 7.15 Comma >operator, on page 192 of C Programming Language doesn't state much >on this. > >Dennis Chen The first example has an expression (a function) comma separated with a statement. The comma operator is supposed to evaluate to the rightmost expression. Since the rightmost item here is not an expression, you get the problem. The second example illustrates this -- exit is a function, thus an expression. --- Mark Nagel >>> nagel@iris.ucdavis.edu ARPA >>> mdnagel@ucdavis BITNET >>> ..!{ucbvax,sdcsvax,lll-crg}!ucdavis!iris!nagel UUCP