9fans archive / 2001 / 06 / 447 / prev next
From: rog@vit...
Subject: Re: [9fans] calling function with (variable number of) parameters
Date: Thu, 21 Jun 2001 15:33:15 +0100
> So save space for n + 1 parameters on the stack; the last won't be used
> by your called function, and you could store the number of parameters in
> it. When you return, pop the last item off the stack, and use that to
> recalculate the frame pointer.
no actually, parameters are pushed on last first, so the last one
you've pushed (the one you've got access after the return) is the first
parameter to the function (which doesn't expect it).
i think that probably the only way of getting around the problem is to
change the prototype of the called function so that the first parameter
signifies the number of parameters.
the only other alternative is if the function is guaranteed to be
non-reentrant (fat chance) in which case you could store the number of
params in a static variable.
of course, that then makes it incompatible with the original...
cheers,
rog.