c calling conventions

C calling convention we all know defines a way how the parameters are pushed onto the stack.
My question is when and how does this C calling conventions matters to a user?
When the user will have to bother about the calling conventions in his project?

I think, if you do something like this
for instance:

function( t++, t);

does the 2nd parameter end up before or after the t++?
not defined I believed.

Order of evaluation of function arguments is not defined. In fact it is a portability problem. The only thing that can be said is that the arguments will have been fully evaluated (it is a sequence point) before the arguments are passed to the called function.

BEB's example is a disaster waiting to happen.

By calling conventions do you mean _CDECL and _STDCALL? That is independant of the example given in the above post. Order of evaluation and the order arguments are pushed is not necessarily related.

1 Like

There are some security issues that can also arise if a user is intimately familiar with how parameters are pushed on to the stack. Buffer overflow attacks, stack smashing, and heap smashing are all common ways to attack vulnerable code. Additionally, format string issues might allow a user to view what is on the stack. Imagine if you wrote a C program that takes user input and prints back what the user typed. Now imagine what would happen if the user typed "%x%x%x%x%x%x..." it would essentially print whats on the stack in hex format.

thanks jim and jasondj for the replies
yes by calling conventions I mean _CDECL and _STDCALL.
when should a user have to bother about it?

only when you are porting C code between windows (x86) and unix

1 Like