Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!killer!convex!uunet!mcvax!dkuug!ambush!ambone!leif From: leif@ambone.UUCP (Leif Andrew Rump) Newsgroups: comp.lang.c Subject: Re^2: QuickC Message-ID: <140@ambone.UUCP> Date: 27 Aug 88 15:45:22 GMT References: <8808261424.AA11504@ucbvax.Berkeley.EDU> Organization: AmbraSoft A/S (Denmark) Lines: 37 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! >I get '4' as an answer. So I thought maybe it was keeping the result >of the last operation, so I added some dummy lines, >square(num) >int num; >{ > int dummy; > num = num*num; > dummy=222; >} >but the call STILL works... Can anyone shed some light onto this? >WHY does it work? My answer has not been tested but I'm quite sure that this is the right answer to your question: 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! Leif Andrew Rump, Ambrasoft A/S, Roejelskaer 15, DK-2840 Holte (Denmark) UUCP: leif@ambone.dk, phone: +45 2424 111; ABC BBS: +45 68 00 544 (2:505/38) Please note the node-change: Ambone, Italian for a pulpit (The following interpretations emerged Am_bone, Ambrasoft A/S bone when Ambone was put down on paper and Amb_one, Ambrasoft A/S #one accepted - they are solely mine!!!!!) ...