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

Re: [f-cpu] calling conventions



On Fri, 7 Jun 2002 12:48:06 +0200, Christophe wrote:
>[Thomas]
>
>I'm sorry but Delphi and Kylix mix register and stack parameters in
>their
>calling convention and all work OK without any problems. It's a very
>speed call system and simple to use.
>
>[I]
>
>C only,
>
>Write your prototype :
>
>int open (char const *,int,...);
>  ==> r1 open (r1,r2,stack);
>
>Now write your implementation :
>
>int open (char const *,int,int) { }
>  ==> r1 open (r1,r2,r3)
>
>And now, try to call 'open' with the third argument :
>
>.... = open ("...",...,...);
>  ==> BANG !!!!!

False you must have same register and stack assignment : you first choose
the number of argument you can put in register and all was ok :
Delphi/Kylix use 3 register so you obtain this

int open (char const *,int,...);
  ==> r1 open (r1,r2,r3);

and

int open (char const *,int,int) { }
  ==> r1 open (r1,r2,r3)

if you would two you obtain this :

int open (char const *,int,...);
  ==> r1 open (r1,r2,stack);

and

int open (char const *,int,int) { }
  ==> r1 open (r1,r2,stack)

Store in register or stack do not depend on paremters type.
>
>Why ? because your header use "r1 open (r1,r2,stack)" but finally
>you will get
>the call address of "r1 open (r1,r2,r3)". So your implementation is
>unable to
>handle the third argument since it is in the stack and not in r3.
>
>Delphi and Kylix, when you use pascal functions, uses their fast
>calling
>convention because they don't need to be compatible with other
>languages. If
>they want to call C functions, they just took the C calling
>convention (for
>IA32, all parameters in stack) especially if they want to access
>glibc or
>likes.
>

They're no diference between Pascal and C for this point, all two
interact cleanly with other languages, just delphi/kylix use a special
fast call convention for internal call, but you can choose any call
convention for any call.
If you could do this in C you can optimize each call...

--
Thomas Lavergne                       "Le vrai rêveur est celui qui rêve
                                       de l'impossible."  (Elsa Triolet)
thomas.lavergne@laposte.net                                      
d-12@laposte.net    ICQ:#137121910     http://assoc.wanadoo.fr/thallium/


*************************************************************
To unsubscribe, send an e-mail to majordomo@seul.org with
unsubscribe f-cpu       in the body. http://f-cpu.seul.org/