calling convention: right to left Vs. left to right

Jul 15, 2011 at 10:56am
In C language why it has been the convention that function argument shall be pushed on the stack from "Right to Left" it could have been "Left to Right". Is there any advantage/disadvantage? Obviously the answer to this call will be different.
int a = 1 ;
printf ( "%d %d %d", a, ++a, a++ ) ;

We could have standardized the other way too.
Jul 15, 2011 at 1:45pm
There are many ways to handle arguments. The cdecl method just seemed the most convenient at the time.

BTW, the calling convention is not bound to the language (AFAIK), but to the processor architecture.

More reading:
http://en.wikipedia.org/wiki/Calling_convention
http://en.wikipedia.org/wiki/X86_calling_conventions

Hope this helps.
Jul 15, 2011 at 5:34pm
Is there any relation to the variable number of arguments which was needed to be supported, where the first argument was the most important and required to be present right at the top of the stack.
e.g. (argc,argv) OR printf("%...format " , arg1, arg2...)

Is there no relation at all??

Agreed that calling convention has to be bound to the processor architecture. I guess left to right or right to left was not based on process architecture but more from language perspective which I wanted to understand.

Most of the articles just state that it is right to left, no one tells the logic behind that. ( why it was felt to be more convenient)
Jul 15, 2011 at 9:17pm
No. Well, maybe. Variable arguments (as C and C++ implement them) have always been a hack. They do require a caller-cleanup convention.

As for the push order, when given two equally valid, useful choices, which do you make? I am not privvy to more information about it (or I have forgotten). You may need to ask Mr. Ritchie.
Topic archived. No new replies allowed.