Compiler bug? (return values from functions)

Curtis Johnson x6241 curtis at se-sd.UUCP
Sat Dec 6 06:58:49 AEST 1986


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 at se-sd.UUCP
    ...!sdcsvax!ncr-sd!se-sd!curtis
NCR Corp. Systems Engineering, San Diego 



More information about the Comp.lang.c mailing list