Value, value, who's got the value?

Henry Spencer henry at utzoo.uucp
Fri Apr 28 02:32:59 AEST 1989


In article <1044 at itivax.iti.org> scs at vax3.iti.org (Steve Simmons) writes:
>int	func1()
>{
>	int b ;
>	b = 2 ;
>}
>int	func2()
>{
>	int c = 3 ;
>	c ;
>}
> ...
>Several questions: why does the OS make a difference; why does
>System V get it 'right' (even tho the code is wrong); why do
>none of these flag func2 as having a syntax error?

It's the compiler, not the OS, that makes the difference.  Neither of
those functions returns a value at all.  Some compilers will fortuitously
build the value of the last expression you evaluate in the same register
that is used to return a value, so it will appear that the "right" value
was returned.  There is no syntax error in func2, although the last
statement in func2 evaluates an expression with no side effects and then
throws the value away, which is kind of pointless (but legal).
-- 
Mars in 1980s:  USSR, 2 tries, |     Henry Spencer at U of Toronto Zoology
2 failures; USA, 0 tries.      | uunet!attcan!utzoo!henry henry at zoo.toronto.edu



More information about the Comp.lang.c mailing list