[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [f-cpu] calling conventions



On Fri, Jun 07, 2002 at 12:27:25AM +0200, Christophe wrote:
[...]
> > You see, it's no problem at all. There is a little overhead when dealing
> > with variable argument lists, but that's ok as long as functions with
> > a fixed number of arguments run fast.
> 
> As i told you functions with no variable arguments are given in register.

And as I told you (repeatedly!), *all* functions must use the same calling
conventions - and that will be the one for fixed-args functions because
it's the default case and it's fastest.

[...]
> > No. All functions MUST use the same calling conventions, whether they
> > take a variable number of arguments or not. (The C99 standard does not
> > require it - in fact, it contains rules that avoid this situation -
> > but there is a *lot* of C code out there that won't work otherwise).
> >
> 
> I'm sorry, but it isn't what occurs in gcc.
> 
> For example, gcc for SH use registers for the four first arguments.
> 
> gcc for IA32 - when regparm option is used - use registers as possible except
> when this function has variable arguments (all stack parameters in that case).

Ever linked object files that were compiled with different `regparm'
settings? *BOOM*.

[...]
> And I don't see why the calling conventions could not be the same for all the
> functions if we consider those rules :
> 
> - fix arguments always as possible in registers, the rest in stack

Because you never know which arguments are fixed and which aren't, due
to C's linking semantics (C doesn't have type-safe linking like C++).
E.g. open() is often declared as

	int open(const char *name, int mode, ...);

(because it can take two or three arguments) but in fact it may be
(and eventually is) implemented as

	int open(const char *name, int mode, int perms) {
		...
	}

These two declarations must be compatible, or else a lot of `legacy'
C code will break.

-- 
 Michael "Tired" Riepe <Michael.Riepe@stud.uni-hannover.de>
 "All I wanna do is have a little fun before I die"
*************************************************************
To unsubscribe, send an e-mail to majordomo@seul.org with
unsubscribe f-cpu       in the body. http://f-cpu.seul.org/