Pelles C forum

C language => Beginner questions => Topic started by: Manish Aggarwal on September 12, 2015, 03:16:06 AM

Title: A doubt on calling convention of C
Post by: Manish Aggarwal on September 12, 2015, 03:16:06 AM
Basically the C language calling convention is from right to left. So I passed the values as shown. As per the convention , to what I think, b=l and j=a......but here what happens actually is b=a,j=i....Please explain this?

‪#‎include‬<stdio.h>
int pass();
int main(void)
{
int i = 135, a = 130, k,l=0 ;
k = pass ( i, a,l) ;
printf ( "\n%d\n", k ) ;
}
int pass ( int j,int b)
{
int c;
printf("b=%d",b);
printf("\nj=%d",j);
c = j + b ;
return ( c ) ;
}
Title: Re: A doubt on calling convention of C
Post by: TimoVJL on September 12, 2015, 08:26:14 AM
Parameters are pushed into stack in that order. In function those are in same order.
Look https://en.wikipedia.org/wiki/X86_calling_conventions
In assembly[40101B] push dword ptr [l]
[40101E] push dword ptr [a]
[401021] push dword ptr [i]
[401024] call pass
Title: Re: A doubt on calling convention of C
Post by: Manish Aggarwal on September 12, 2015, 08:43:51 AM
hmmm.............Got that.........
Thanks Sir :)