Re: Passing too many parameters to a function?
Re: Passing too many parameters to a function?
- Subject: Re: Passing too many parameters to a function?
- From: Camillo Lugaresi <email@hidden>
- Date: Mon, 18 Sep 2006 22:06:33 +0200
On 20/ago/06, at 12:17, Uli Kusterer wrote:
Hi,
you know how main() can be declared with varying parameter counts,
like
int main()
or
int main( int argc, const char* argv* )
and even more. Does this work for any function? If I pass a
function more parameters than it actually uses, is that safe with
OS X's current Mach-O ABIs?
I would like to have plugins in my app be prepared for a future
expansion of the plugin protocol, which would require them to pass
an additional parameter (that my app isn't using right now) to the
callbacks they send. Since I'm gonna be releasing a new plugin SDK
with the first universal version, I thought this would be a good
opportunity to add this change, so that all recompiled Xes would
run unchanged on the future new system and I can drop the old code
that doesn't have this parameter.
I trid googling for "Mach O ABI too many parameters" and stuff like
that, but I just couldn't find any clues there, so if anyone knows
where I can find this documented or even has an answer, that would
be cool!
I just read this thread, and although it's old, it seems that it did
not reach a conclusion, so forgive me for resurrecting it. :)
If you look at the PPC and IA32 ABIs, it seems that what you want to
do is safe. Here is the PPC32 ABI:
<http://developer.apple.com/documentation/DeveloperTools/Conceptual/
LowLevelABI/Articles/32bitPowerPC.html>
Note that space for the parameters is allocated in the caller's stack
frame (most parameters are passed in registers, but space is still
allocated for them on the stack). On entry, the called function sees
a 24-byte linkage area at SP, and the parameter area at SP+24. The
parameter area is large enough to hold parameters for all functions
the caller wants to call; the callee does not need to know its exact
size, since arguments are allocated in left-to-right order at
increasing addresses starting at SP+24: the callee just looks at the
lowest chunk of the parameter area, corresponding to the leftmost
arguments (however many it expects), and ignores the rest. The same
goes for the arguments passed in registers: the callee will use the
ones it needs, and ignore/clobber the rest.
Here is the IA32 ABI: <http://developer.apple.com/documentation/
DeveloperTools/Conceptual/LowLevelABI/Articles/IA32.html>
The parameter area is allocated and deallocated by the caller, and
arguments are allocated in order starting at SP and growing upwards.
The situation is the same as on PPC.
Therefore, I'd say you're safe to add parameters as you wish. Of
course, the later versions of the callee must be prepared to receive
garbage in the extra arguments from older callers.
Camillo
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden