Function returning Structure: How does it work?
Michael Meissner
meissner at osf.org
Thu May 31 00:21:10 AEST 1990
In article <18222 at well.sf.ca.us> rld at well.sf.ca.us (Rick Davis) writes:
| In article <1990May28.235336.5338 at 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 at osf.org phone: 617-621-8861
Open Software Foundation, 11 Cambridge Center, Cambridge, MA
Catproof is an oxymoron, Childproof is nearly so
More information about the Comp.lang.c
mailing list