Path: utzoo!attcan!uunet!tektronix!sequent!bills From: bills@sequent.UUCP (Bill Sears) Newsgroups: comp.lang.c Subject: Re: Value, value, who's got the value? Message-ID: <15233@sequent.UUCP> Date: 27 Apr 89 21:35:21 GMT References: <1044@itivax.iti.org> Reply-To: bills@sequent.UUCP (Bill Sears) Organization: Sequent Computer Systems, Inc Lines: 29 In article <1044@itivax.iti.org> scs@vax3.iti.org (Steve Simmons) writes: > >Several questions: why does the OS make a difference; why does >System V get it 'right' (even tho the code is wrong); > Actually, there is no "right" output for this program. According to K&R (version 1, sorry) pp23-24: "a 'return' statement with no expression causes control, but no useful value, to be returned to the caller, as does "falling off the end" of a function by reaching the terminating right brace." Some compilers pass return expressions back through registers. If no explicit value is returned, the value which is used is whatever value is in the register when it is evaluated. Evidently, the SYSV compiler is using the return register to do the computation that you specify in the function. Since no explicit value is returned, the value that is left in the register when control returns to the caller is the value of the expression in the function. > >why do none of these flag func2 as having a syntax error? > Because func2 doesn't have a syntax error. C treats an expression the same way it treats a statement so that functions that return a value which is sometimes ignored don't fail. For example: The close(2) system call returns a value (and hence is an expression) to indicate the success or failure of the operation. But most programs do not check the return value (what are you supposed to do? The usual way close will fail is if the supplied file descriptor is not open. In which case the outcome is the same, the fd is closed :-).