This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: call through pointer of function with variable arguments
On Wed, 2003-06-04 at 19:42, Geoff Keating wrote:
> Stephen Biggs <xyzzy@hotpop.com> writes:
>
> > Given this code:
> > #include <stdio.h>
> > char buf[2];
> >
> > int (*gfp)(char *, const char *, ...);
> > int (*gfp1)(const char *, ...);
> >
> > void f (fp,fp1)
> > int (*fp)(char *, const char *, ...);
> > int (*fp1)(const char *, ...);
> > {
> > (*fp1)("%.0f\n",5.0);
> > (*fp)(buf, "%.0f", 5.0);
> > }
> >
> > void h(void)
> > {
> > gfp = sprintf;
> > gfp1 = printf;
> >
> > (*gfp1)("%.0f\n",5.0);
> > (*gfp)(buf, "%.0f", 5.0);
> > }
> >
> > int main()
> > {
> > f (&sprintf,&printf);
> > h ();
> > return 0;
> > }
> >
> > ... in both the cases, by the time I get to the point where I receive an
> > expression for the call (in either f or g), the function pointer value
> > has already been moved to a register and no prototype information is
> > available, since all I have is the function address (in my port, the
> > arguments for the current call are already saved aside). The
> > proprietary machine I am porting to is sensitive to whether a call has
> > variable arguments or not and has a different calling sequence based on
> > that, but how can I know?
>
> You have to remember from the FUNCTION_ARG macro.
>
> > Are there any other machines that already have been ported that have
> > this sensitivity?
>
> rs6000 has similar things. Look at CALL_V4_SET_FP_ARGS in that port.
>
> --
> - Geoffrey Keating <geoffk@geoffk.org>
Thank you!