Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!cmcl2!yale!husc6!panda!genrad!decvax!decwrl!pyramid!gould9!ncr-sd!se-sd!curtis From: curtis@se-sd.UUCP (Curtis Johnson x6241) Newsgroups: comp.lang.c Subject: Re: Compiler bug? (return values from functions) Message-ID: <929@se-sd.UUCP> Date: Fri, 5-Dec-86 15:58:49 EST Article-I.D.: se-sd.929 Posted: Fri Dec 5 15:58:49 1986 Date-Received: Sat, 6-Dec-86 21:39:37 EST References: <898@chalmers.UUCP> Reply-To: curtis@se-sd.UUCP (Curtis Johnson) Organization: NCR Corporation, SE - San Diego Lines: 47 I thought Per might have a version of the compiler that has since been improved, so I compiled his program (on a Tower XP w/3.00.04), ran it and found that 0400 was returned by a(). I looked in K&R for hints and found some ambiguous language describing the use of the "return" statement. On page 68 (chapter 4.1), is the statement: ... "Any expression can follow return: return(expression)" ... There is not a word in this section concerning the usage of parentheses with the return statment. Hmmmmmm... On page 203 (Appendix A: C Reference Manual, section 9.10 Return Statement) I found: ... "A function returns to its caller by means of the return statement, which has one of the forms return ; return expression ;" ... Again, there is no wording concerning the presence ( or absence ) of parentheses. Looking into the definition of "expression" is no help as the only mention of parentheses with respect to expressions is made concerning primary expressions only ( which this case is not). The ANSI draft standard for "C" (July 9, 1986) agrees with K&R to the extent that parentheses are not explicitly required with the return statement. Since K&R and the draft ANSI standard don't mention parentheses with respect to the return statement, I would guess that implementations that require parentheses are wrong. -- Curtis Johnson curtis@se-sd.UUCP ...!sdcsvax!ncr-sd!se-sd!curtis NCR Corp. Systems Engineering, San Diego