#include <iostream>
usingnamespace std;
void PrintOrder(unsignedlong a, unsignedlong b, unsignedlong c, unsignedlong d)
{
cout << a << b << c << d << endl;
}
unsignedlong Staticount()
{
staticunsignedlong v = 0;
return(v++);
}
int main()
{
PrintOrder(Staticount(), Staticount(), Staticount(), Staticount());
cin.sync();
cin.ignore();
}
My output is 3210, my compiler in VC++2008 Express evaluates the parameters from right to left, which was the opposite of what I thought. I'm curious as to the order your compiler(s) evaluate(s) parameters, as the order is undefined. This tricked me up once, because I assumed the parameters to a function call would be evaluated from left to right, I spent hours debugging this until someone finally pointed it out to me >_<
If I'm not mistaken, it's naturally read from right to left because of the nature of the underlying assembly. I'm not to avid in how Assembly works (well, I understand ASM, but not the concepts that surround it) so I really can't be certain about it.
A teacher once told me it's done this way to implement variadic functions. If the parameters are pushed right to left, the stack will look like this:
<variadic parameters>
3rd parameter
2nd parameter
1st parameter
Then, by passing a pointer to the third parameter and since the beginning of the stack frame is always known, it's easy to determine how many parameters were passed.