Newsgroups: comp.lang.c
Path: utzoo!henry
From: henry@utzoo.uucp (Henry Spencer)
Subject: Re: Value, value, who's got the value?
Message-ID: <1989Apr27.163259.23476@utzoo.uucp>
Organization: U of Toronto Zoology
References: <1044@itivax.iti.org>
Date: Thu, 27 Apr 89 16:32:59 GMT

In article <1044@itivax.iti.org> scs@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@zoo.toronto.edu
