1) operation rules:
++i means adding 1 to I before using I.
I++ means to use I first and then add 1 to it.
2) Input sequence of function parameters:
Function parameter stack order of c/c++
C/c++ function parameter stack order.
I once read an article that the stacking order of c/c++ parameters is from right to left and pascal parameters are from left to right.
I lost a lot of people for this sentence. It doesn't matter, we are thick-skinned anyway.
To sum up: the parameter stack order of the compiled c/c++ program is only related to the compiler!
Some common compiler calling conventions are listed below.
VC6:
Call the convention stack to clear parameter passing.
__cdecl callers walk through the stack from right to left.
The __stdcall function body is passed from right to left in the stack.
__fastcall function body from right to left, first register (ECX, EDX), then stack.
By default, this pointer is passed through ECX in the Thiscall function body, and other parameters are stacked from right to left.
__cdecl is the default calling convention of C\C++; There is no keyword thiscall in the calling convention of VC, which is the default calling convention of class member functions;
The calling convention of the main (or wmain) function in C\C++ must be __cdecl and cannot be changed;
The default calling convention can usually be changed through compiler configuration. If your code relies on calling conventions, please clearly indicate which calling convention you need to use.
C++Builder6:
Call the convention stack to clear parameter passing.
__fastcall function body from left to right, first register (EAX, EDX, ECX), then stack (Delphi compatible register).
(the register is equivalent to __fastcall)
The __pascal function body goes through the stack from left to right.
__cdecl callers go through the stack from right to left (compatible with the default calling convention of C\C++).
__stdcall function body passes through the stack from right to left (compatible with __stdcall in VC).
__msfastcall function body from right to left, first register (ECX, EDX), then stack (VC compatible __fastcall).
The above information comes from an article by Hou Sisong: /index.php? Option = content & task = view & id = 29 & itemid = 31.
Because of limited ability and resources, I can only find these things. The main difference lies in fastcall. Vc is the first two parameters put into the register, and the latter is the stack. Bcb is that registe used by the first three parameter.
What's more, a friend said that if there are more than seven parameters, the first five parameters are passed from left to right, and the latter ones are passed from right to right. Don't believe all the above.
How do you decide your compilation order?
# include & ltstdio.h & gt
int f(int i,int j,int k);
int main()
{
Static int I = 0;;
f(i++,i++,i++);
Returns 0;
}
int f(int i,int j,int k)
{
int l;
int g;
printf("k=%d:[%x]\n ",k & amp; k);
printf("j=%d:[%x]\n ",j & amp; j);
printf("i=%d:[%x]\n ",I,& ampI);
printf(" _ _ _ _ _ _ _ _ _ _ _ _ _ _ \ n ");
printf("l:%x\n ",& ampl);
printf("g:%x\n ",& ampg);
}
Look at k-> The ascending order of addresses of I and L->; Whether the order of g is the same, if so, from right to left, otherwise from left to right.
PS:
Originally, the value of printing parameters was used to judge which one entered the stack first, but the result was criticized by a friend.
He said: stacking order and parameter calculation order are not the same thing, and it is safer to look at the address.
//Friends who have treated it as a joke.
This article is from CSDN blog, please indicate the source:/yingqunren/archive/2009/03/11/3979270.aspx.