"Mohamed Shafi" <[EMAIL PROTECTED]> writes:

> I am working with a private target(GCC v4.1.1).
> For my target the function arguments are passed through registers.
> For this purpose 4 registers are used. If the no. of arguments are
> more than 4, the remaining arguments are passed through stack.
> 
> But for varargs the arguments are pushed into the stack by the caller 
> function.

These days the usual style is to handle arguments for normal and
varargs functions in exactly the same way.  This avoids errors when
calling a function without a proper prototype in scope.  But certainly
what you describe is a valid way to implement a backend.

> void foo(char *name, int d, int e, int f, int g)
> {
>   printf("\nname = %s\n13 = %d\n72 = %d\n89 = %d\n5  = %d\n", name,d,e,f,g );
> }
> 
> void bar(char *name, ...)
> {
>   void **arg;
>   arg = __builtin_apply_args();
>    __builtin_apply(foo, arg, 24);
> }

For your platform, __builtin_apply will only work when the callee has
the same signature as the caller.  __builtin_apply has no support for
changing the way that arguments are passed.  It simply passes the
arguments to the callee in the same way that they were passed to the
caller.

Before you really dig into this, do you care?  __builtin_apply only
exists to implement the Objective C runtime.  And in fact it is
generally considered desirable to change that code to use libffi
instead, in which case __builtin_apply will probably be deprecated and
removed.  If you don't need to compile Objective C, I wouldn't worry
about __builtin_apply.

Ian

Reply via email to