gurulet aptitude test (and bug)

greg yachuk greggy at infmx.UUCP
Tue Dec 13 05:45:46 AEST 1988


In article <44200023 at uicsrd.csrd.uiuc.edu> mcdaniel at uicsrd.csrd.uiuc.edu writes:
>II    Line 4: the declaration of "struct zztop" was probably meant to
>      have a ";" after the closing "}".  Without it, sub1()'s return
>      type is "struct zztop":
>            struct zztop {int a; int b;} sub1() {...}
>      With a ";", sub1()'s return type is an int.  This point is
>      irrelevant, really, since sub1's return value is always ignored.
       ^^^^^^^^^^
Actually, this is THE bug.  A struct is (traditionally) returned by address
(or implicitly by copying it to a generally known place).  It is then the
responsibility of the caller to not only remove the parameters from the
stack, but also to copy the returned value from where-ever to some local
place (variable or temp-location).  On a SUN-3, it appears to return the
address.  With this example code, a zero just *happens* to be the returned
value, since sub1() does not explicitly return a value.  Attempting to
dereferece location zero causes the core dump.

>             Tim, the Bizarre and Oddly-Dressed Enchanter

	-greg

Greg Yachuk	Informix Software Inc., Menlo Park, CA	(415) 322-4100
{uunet,pyramid}!infmx!greggy	why yes, I DID choose that login myself

"May I remind you that here at Atherton, Pembroke & Wills we do *not*
take fashion risks?"		-- Leo Cullum



More information about the Comp.lang.c mailing list