Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!wuarchive!uunet!snorkelwacker!paperboy!meissner From: meissner@osf.org (Michael Meissner) Newsgroups: comp.lang.c Subject: Re: Function returning Structure: How does it work? Message-ID: Date: 30 May 90 14:21:10 GMT References: <1990May28.215331.29333@agate.berkeley.edu> <1990May28.235336.5338@Neon.Stanford.EDU> <18222@well.sf.ca.us> Sender: news@OSF.ORG Distribution: usa Organization: Open Software Foundation Lines: 30 In-reply-to: rld@well.sf.ca.us's message of 30 May 90 04:32:55 GMT In article <18222@well.sf.ca.us> rld@well.sf.ca.us (Rick Davis) writes: | In article <1990May28.235336.5338@Neon.Stanford.EDU>, Dave Eisen writes: | > | > Of course, this | > can lead to a great deal of copying so most of the time you're better off | > arranging things for the function to have type STRUCT * instead. | > | | I can't agree with this too strongly. Passing entire structures back | and forth is almost always a serious waste of time and stack space. | Indeed, there are circumstances where it is necessary, (i.e communications) | but most of the time you're much better off with the structure pointer. | Also, some implementations of C won't even let you try. Code portability | alone works for me. But a clever compiler could optimize: struct foo func(), var; var = func(); and pass the address of var (assuming it returns structures by passing a pointer as a hidden argument), so that a temporary and a structure copy are not required. -- Michael Meissner email: meissner@osf.org phone: 617-621-8861 Open Software Foundation, 11 Cambridge Center, Cambridge, MA Catproof is an oxymoron, Childproof is nearly so