Call a convention and evaluation procedure

I know that C ++ does not indicate the order in which parameters are passed to the function. But if we write the following code:

void __cdecl func(int a, int b, int c)
{
       printf("%d,%d,%d", a,b,c);
}
int main()
{
   int i=10;
   func(++i, i, ++i);
}

Can we reliably say that there will be a solution 12,11,11, since __ cdecl guarantees that the order of passing arguments is right?

+5
source share
4 answers

According to the Standard, you need to understand and distinguish between two things:

  • C ++ does not indicate the order in which the parameters are passed to functions (as you said yourself that it was true!)
  • C ++ does not determine the order in which function arguments are evaluated [expr.call].

, , __cdecl , . , , left-to-right right-to-left; !

, .

, Microsoft ++, . , MSV++ IF, !


func(++i, i, ++i);

, undefined, i .

+12

( - ), undefined .

0

, . . , __stdcall , __stdcall, , .
, , , , .

, , . , fn(a, b, c) GCC

push c
push b
push a 
call fn

sub esp, 0xC  
mov [esp+8], c
mov [esp+4], b
mov [esp], a
call fn

, .

0

, C , , " undefined". , int ~ 0U undefined, C , int -1 ( -493, ). , , -1. __cdecl C , , , ; C , , .

0
source

All Articles