Path: utzoo!attcan!uunet!lll-winken!lll-tis!helios.ee.lbl.gov!pasteur!ames!mailrus!utah-gr!uplherc!sp7040!obie!wes From: wes@obie.UUCP (Barnacle Wes) Newsgroups: comp.lang.c Subject: Re: Re^2: QuickC Summary: Well, probably not! Message-ID: <175@obie.UUCP> Date: 31 Aug 88 03:12:55 GMT References: <8808261424.AA11504@ucbvax.Berkeley.EDU> <140@ambone.UUCP> Organization: the Well of Souls Lines: 29 TURGUT@TREARN.BITNET (Turgut Kalfaoglu) writes: % square(num) % int num; % { % num = num*num; % } % % OK? There is no 'return' statement in the function. However, it works! % WHY does it work? In article <140@ambone.UUCP>, leif@ambone.UUCP (Leif Andrew Rump) writes: > When you call a function i C the parameters is put on the stack. You > function uses the stack to keep the variable num and when the function > return the result is popped from the stack - which (unfortunately(!) > is the temporary variable num! Turgut, what C compiler are you using? Many compilers treat one register as an 'accumulator' and do most of their 'temporary' arithmetic using that register. This same register is quite often used to pass the return value back to the caller for a function. On the 680x0, register d0 is quite often used. Probably what you have experienced is the compiler leaving the result of (num*num) in the register used to pass results, and the main program has picked up the value in this register. I certainly wouldn't count on it happening this way all the time, though. :-) :-O B-) ;-) 8-) -- {hpda, uwmcsd1}!sp7040!obie!wes "Happiness lies in being priviledged to work hard for long hours in doing whatever you think is worth doing." -- Robert A. Heinlein --