Function Argument Question

Mike Stump mrs@windriver.com
Tue Dec 12 15:11:00 GMT 2000


> Date: Tue, 12 Dec 2000 16:15:13 -0600
> From: Davy Durham <david.durham@wcom.com>
> To: gcc@gcc.gnu.org

> The script is invoked by a C program..... but before it is, it sets
> a table of addresses that are pointers to the C functions I want to
> call...

> However, what I need to know how to do is to say at what address the
> arguments begin...

We talk about this problem on this list (one one like it) every now
and then.  The short answer is, no, there isn't a portable C method to
do it.  For non-portable solutions, see the section at the end (quoted
from the manual).  It is the only thing we have the resembles what you
want to do.  Search __builtin_apply_args in the mailing list, and you
can find the past discussions, think there may even be the names of
two packages (libraries) that help solve this problem.

Good Luck.


@section Constructing Function Calls
@cindex constructing calls
@cindex forwarding calls

Using the built-in functions described below, you can record
the arguments a function received, and call another function
with the same arguments, without knowing the number or types
of the arguments.

You can also record the return value of that function call,
and later return that value, without knowing what data type
the function tried to return (as long as your caller expects
that data type).

@table @code
@findex __builtin_apply_args
@item __builtin_apply_args ()
This built-in function returns a pointer of type @code{void *} to data
describing how to perform a call with the same arguments as were passed
to the current function.

The function saves the arg pointer register, structure value address,
and all registers that might be used to pass arguments to a function
into a block of memory allocated on the stack.  Then it returns the
address of that block.

@findex __builtin_apply
@item __builtin_apply (@var{function}, @var{arguments}, @var{size})
This built-in function invokes @var{function} (type @code{void (*)()})
with a copy of the parameters described by @var{arguments} (type
@code{void *}) and @var{size} (type @code{int}).

The value of @var{arguments} should be the value returned by
@code{__builtin_apply_args}.  The argument @var{size} specifies the size
of the stack argument data, in bytes.

This function returns a pointer of type @code{void *} to data describing
how to return whatever value was returned by @var{function}.  The data
is saved in a block of memory allocated on the stack.

It is not always simple to compute the proper value for @var{size}.  The
value is used by @code{__builtin_apply} to compute the amount of data
that should be pushed on the stack and copied from the incoming argument
area.

@findex __builtin_return
@item __builtin_return (@var{result})
This built-in function returns the value described by @var{result} from
the containing function.  You should specify, for @var{result}, a value
returned by @code{__builtin_apply}.
@end table


More information about the Gcc mailing list