Function Argument Question

Michael Meissner meissner@cygnus.com
Wed Dec 13 15:22:00 GMT 2000


On Wed, Dec 13, 2000 at 10:32:34AM -0600, Davy Durham wrote:
> Michael Meissner wrote:
> 
> >
> > Not necessarily.  The compiler on many machines receives the first n arguments
> > in registers and not on the stack.  Some machines reserve space on the stack to
> > store these arguments, and some do not, in which case it stores the argument at
> > some location in the stack frame.  Also for char/short/float arguments if a
> > prototype was not in scope the compiler receives the argument as the widened
> > type and then converts it to the narrowed type, and stores it some place on the
> > stack.
> >
> 
> Yup, but I found the extension  for a function attribute:
> 
> void func(...) __attribute__ ((regparm(0)));
> 
> which is supposed to make it not pass any args in registers..

Which is machine specific to the x86.  All of the world is not an x86.

> Yup... I realize this....  I wish there were an exension that would make functions
> behave to some (probably non existant) IEEE standard for inter-language
> infacing...
> 
> Something like:
> 
> __common_call__ void foo(int a, float b, char c);
> 
>     Would mean.... pass all arguments in left-to-right order in a contiguous
> section of memory.. where the arguments are aligned to the value specified in the
> first 16bits interpreted as an unsigned 16bit integer... And space for the return
> value appears at the end (or beginning) of that contiguous memory.. And it is the
> responsibility of the caller to cleanup... etc
>     Or something like that..   And if all languages has this extension in some
> form a utopia would for and all homelessness and poverty would cease...... ;)

And until somebody does the work, contributes it, gets it approved and checked
in, it will remain a dream.

>     Anyway, what I'm doing now is using __builtin_apply(...)  from within my
> script interpreter to call the C function.... I looked around in the gcc code
> enough to know that the first part of the void * argument contains the address
> where the arguments should start (order of args I'm still not quite sure of)...  I
> haven't played with return value yet and make just required them to be returned in
> an argument...
>     But, what I have is working for now....   I looked around and there doesn't
> seem to be any documentation on the structure of what __builtin_apply_args
> returns...  This would probably help me...

And also there might be some machines that never supported __builtin_apply
because it was so poorly documented, and really only used in Objective C (I
certainly was guilty of that when I was one of the PowerPC maintainers).

-- 
Michael Meissner, Red Hat, Inc.  (GCC group)
PMB 198, 174 Littleton Road #3, Westford, Massachusetts 01886, USA
Work:	  meissner@redhat.com		phone: +1 978-486-9304
Non-work: meissner@spectacle-pond.org	fax:   +1 978-692-4482


More information about the Gcc mailing list