On May 9, 10:00 am, faceman28...@yahoo.com wrote:
On May 9, 11:06 am, "m...@ieee.org" <snorkel...@gmail.com> wrote:
Easy enough to disregard, but I'm trying to understand the rationale.
Were aggregate returns not allowed in K&R? Is there some other good
reason for this warning?
Most systems have a "calling standard" that defines how parameters are
exchanged among functions.Traditionally, function return values are
returned in registers.
When a function attempts to return an a aggregate, it is usually
impossible to return the structure through the designated return
registers (most compilers won't try even if the structure is small
enough).
What the compiler generally has to do is create a dummy parameter and
return the value that way.
1. This usually disrupts the "calling standard". Thus, such a function
may become uncallable from a module created by another compiler.
The right term for calling stardard is ABI (application Binary
Interface).
The different compilers can generate compatible code if they follows
the same ABI.
2. While I hate to discuss efficiency in code, passing and returning
aggregates by value is probably the most inefficient avoidable coding
practice.
I think efficiency is the issue here. Usually, a compiler allocates a
space
in caller for returning struct value and passes that address to
callee. This
usually isn't efficient.
A user can do a better job here.
and the new move-types in C++0x will further improve this. In short,
the programmer.