Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!uwmcsd1!leah!itsgw!steinmetz!uunet!littlei!omepd!pcm From: pcm@iwarpj.intel.com (Phil C. Miller) Newsgroups: comp.lang.c Subject: Re: QuickC Message-ID: <3770@omepd> Date: 28 Aug 88 20:45:20 GMT References: <8808261424.AA11504@ucbvax.Berkeley.EDU> Sender: news@omepd Reply-To: pcm@iwarpj.UUCP (Phil C. Miller) Organization: Intel Corp., Hillsboro Lines: 49 In article <8808261424.AA11504@ucbvax.Berkeley.EDU> TURGUT@TREARN.BITNET (Turgut Kalfaoglu) writes: >The other day, I was struggling with QuickC - a very simply problem, >but really intriguing. Let me know if you can interpret this: >main() >{ > int a,v; > a = 2; > v = square(a); > printf("%d\n",v); >} >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? >-turgut Don't know for sure, but I'll offer a conjecture: The subprogram calling standard for Microsoft C probably has a register doing double duty: it holds input arguments (i.e., num) and also holds the function result (unassigned, but with a residual value set when you assigned a value to the input argument num. Another conjecture: if you were using an optimizing compiler, it would see that the value num was dead (i.e., had no further use in the function square) and the assignment to num would disappear, along with the 'magic' function value assignment. Phil Miller {...}!tektronix!omepd!iwarp!pcm