public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: Variable function arguments and the stack
@ 2007-12-09 14:30 Robert Kiesling
  2007-12-15  8:30 ` Andrew Haley
  0 siblings, 1 reply; 5+ messages in thread
From: Robert Kiesling @ 2007-12-09 14:30 UTC (permalink / raw)
  To: gcc-help

> 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.

Regards,

Robert

-- 
Ctalk Home Page: http://www.ctalklang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Variable function arguments and the stack
  2007-12-09 14:30 Variable function arguments and the stack Robert Kiesling
@ 2007-12-15  8:30 ` Andrew Haley
  0 siblings, 0 replies; 5+ messages in thread
From: Andrew Haley @ 2007-12-15  8:30 UTC (permalink / raw)
  To: Robert Kiesling; +Cc: gcc-help

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Variable function arguments and the stack
  2007-12-06  0:11 ` David Daney
@ 2007-12-06  0:41   ` Robert Kiesling
  0 siblings, 0 replies; 5+ messages in thread
From: Robert Kiesling @ 2007-12-06  0:41 UTC (permalink / raw)
  To: gcc-help

[ Charset ISO-8859-1 unsupported, converting... ]
> 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.

Thanks - the library looks like it should work very nicely.  

Robert Kiesling

-- 
Ctalk Home Page: http://www.ctalklang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Variable function arguments and the stack
  2007-12-06  0:00 Robert Kiesling
@ 2007-12-06  0:11 ` David Daney
  2007-12-06  0:41   ` Robert Kiesling
  0 siblings, 1 reply; 5+ messages in thread
From: David Daney @ 2007-12-06  0:11 UTC (permalink / raw)
  To: Robert Kiesling; +Cc: gcc-help

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.

David Daney

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Variable function arguments and the stack
@ 2007-12-06  0:00 Robert Kiesling
  2007-12-06  0:11 ` David Daney
  0 siblings, 1 reply; 5+ messages in thread
From: Robert Kiesling @ 2007-12-06  0:00 UTC (permalink / raw)
  To: gcc-help


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];

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2007-12-15  8:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-12-09 14:30 Variable function arguments and the stack Robert Kiesling
2007-12-15  8:30 ` Andrew Haley
  -- strict thread matches above, loose matches on Subject: below --
2007-12-06  0:00 Robert Kiesling
2007-12-06  0:11 ` David Daney
2007-12-06  0:41   ` Robert Kiesling

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).