c++默认参数顺序的问题
PHPz
PHPz 2017-04-17 14:58:48
0
3
575

c++默认参数顺序为什么是自右往左?为什么不能从左往右呢?请问这是什么原因。

PHPz
PHPz

学习是最好的投资!

reply all(3)
小葫芦

Can support any number of parameters from right to left

Parameters need to be pushed onto the stack. The stack is first in, last out. If it is pushed into the stack from left to right, it will be very troublesome to find the first leftmost parameter~

Ty80

The stacking order is the same as big-endian and little-endian, either one is acceptable. The default choice of C language is from right to left. It should be because the stack grows downward, so the memory arrangement of pushed parameters will be exactly the same as the order of writing. It may be more convenient to debug and look at the memory. However, actual code access is in the form of stack pointer + offset, so it has no special meaning for the machine.
Whether it can support variable parameters mainly depends on whether the caller is responsible for clearing the stack. For example, __stdcall also pushes the stack from right to left, but the callee clears the stack, so variable parameters are not supported.
__pascal imitates the PASCAL language and pushes the stack from left to right, which is no longer supported by VC.

迷茫

Assume from left to right

int f(int a = 1, int b);

Then did the 1 of your f(1) pass to a or b? . So it cannot go from left to right. .

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template