Path: utzoo!attcan!uunet!husc6!mailrus!uflorida!novavax!hcx1!hcx2!danr From: danr@hcx2.SSD.HARRIS.COM Newsgroups: comp.lang.c Subject: Re: Re^2: QuickC Message-ID: <44100010@hcx2> Date: 6 Sep 88 22:39:00 GMT References: <140@ambone.UUCP> Lines: 41 Nf-ID: #R:ambone.UUCP:140:hcx2:44100010:000:1391 Nf-From: hcx2.SSD.HARRIS.COM!danr Sep 6 18:39:00 1988 /* Written 11:45 am Aug 27, 1988 by leif@ambone.UUCP in hcx2:comp.lang.c */ /* ---------- "Re^2: QuickC" ---------- */ 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!!!!!) ... /* End of text from hcx2:comp.lang.c */