fun() will give you A value, but it's not the RETURNED value, because there was no returned value at all.
Since X was the only value in fun(), it gets printed. In those days, every function returned an int, unless specified otherwise. If no return was given, TC supplied the (iirc), last data it worked with in the function, as an int.
Those C89 and 99 standards were NOT the AT&T standards, as followed by Turbo C.
Last edited by Adak; 12-05-2011 at 10:44 AM.
pelles C outputs x=1.
this has nothing to do with C99. your ancient TurboC compiler simply allows erroneous code and as CTater said, it just happened that the registers worked out to leave the value of X in the right place. If you don't believe it, just use your debugger to step through the code at assembly level.
edit: what i meant by 'nothing todo with C99', I meant C89 should complain and refuse to compile also.
Last edited by dmh2000; 12-05-2011 at 10:50 AM.
You stated that there was no returned value, then you observe that a value was printed. Clearly, that value is the return value, despite the lack of a return statement. As such, when we analyse the program with respect to the C standard, the behaviour is undefined.Originally Posted by Adak
I do not think AT&T ever standardised C, unless you are talking about K&R as a de facto standard. In any case, your disagreement is misplaced. You would have been better off agreeing and then pointing out that Turbo C was implemented before the C standard was published.Originally Posted by Adak
Last edited by laserlight; 12-05-2011 at 11:05 AM.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)