Path: utzoo!utgpu!attcan!dptcdc!tmsoft!mnetor!motto!dave From: dave@motto.UUCP (dave brown) Newsgroups: comp.lang.c Subject: Re: return(struct) implementation Message-ID: <52@motto.UUCP> Date: 7 Mar 89 15:22:58 GMT References: <4425@pt.cs.cmu.edu> Reply-To: dave@motto.UUCP (dave brown) Organization: Motorola Canada Ltd. Lines: 28 In article <4425@pt.cs.cmu.edu> marcoz@MARCOZ.BOLTZ.CS.CMU.EDU.UUCP writes: >Can anybody explain how returning a structure from a function is >typically implemented. Here are two ways that I've seen. The first is in the C compiler for Sys V/68 (Motorola's System V port for the 68000). Any routine that returned a struct has an invisible static area the same size as the struct. The return statement copies the struct value into this area. Code in the calling routine just after the call, copies it to the variable which is to receive it. The second is in the Intermetrics 68000 C compiler. This is a cross- compiler for the 68000, hosted under VAX Ultrix. If a function returns a struct, the compiler inserts a pointer on the stack in front of the first argument. This pointer is the address of the receiving struct variable. The function itself copies the return value through the pointer into the receiving variable. We found out about the second method when a programmer who wasn't using the return value called the function without declaring its return type. His first argument was then taken as the return value address, etc., etc. ----------------------------------------------------------------------------- | David C. Brown | uunet!mnetor!motto!dave | | Motorola Canada, Ltd. | 416-499-1441 ext 3708 | | Communications Division | Disclaimer: Motorola is a very big company | -----------------------------------------------------------------------------