per@chalmers.UUCP (Per Westerlund) (12/03/86)
This small example does not behave as I expected on an NCR Tower XP,
3.00.02 (SysV):
unsigned char
a()
{
int a, b;
a = b = 0200;
return a + b;
}
main()
{
int i;
i = a();
printf("%o\n", i);
}
On the Tower I get 0400, while on a Vax (4.2+) I get 0, which is what
I expected after having read K&R. Should I report this as an error?
Per Westerlund
Chalmers University of Technology
Dept of Computer Sci.
Swedencurtis@se-sd.UUCP (Curtis Johnson x6241) (12/05/86)
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 wescott@sauron.UUCP (Mike Wescott) (12/08/86)
In article <898@chalmers.UUCP> per@chalmers.UUCP (Per Westerlund) writes: > This small example does not behave as I expected on an NCR Tower XP, > 3.00.02 (SysV): ... Yep. It's a bug. A new one to us. A fix has been identified and will be released with all possible speed. It also appears in the Tower32 releases. -Mike Wescott ncrcae!wescott -- -Mike Wescott ncrcae!wescott