This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Variable function arguments and the stack
- From: Andrew Haley <aph at redhat dot com>
- To: Robert Kiesling <kiesling at earthlink dot net>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Sat, 15 Dec 2007 08:30:31 +0000
- Subject: Re: Variable function arguments and the stack
- References: <E1J1NAB-00042M-GW@owl.gateway.2wire.net>
Robert Kiesling writes:
> > David Daney wrote:
> > > Robert Kiesling wrote:
> > > > I trying to write a function that calls libc functions with
> > > > variable arguments - for example, scanf. I would like to do
> > > > this by pushing the arguments onto the stack and then calling
> > > > the function, something like this. (This code is for an x86
> > > > machine.)
> > > >
> > > > static long long int scalar_args[512];
> > > > static char *ptr_args[512][BUFSIZE];
> > >
> > > Use libffi which ships with GCC. Doing things like this is what it was
> > > designed for.
>
> Libffi clobbers either the arguments or the stream argument (the
> first argument before the format string in functions like fprintf
> or sprintf). It should make a distinction whether the args or
> the stream are writeable or readable, and that, of course is the
> idea.
I'm a bit mystified by this comment. All arguments are passed by
value, and are destroyed after the call. What does libffi do that it
should not do?
Andrew.
--
Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SL4 1TE, UK
Registered in England and Wales No. 3798903