Calling Conventions Demystified
-
I must say "thnx" to the writer of article "Calling Conventions Demysified". It is such a good article, i mean im a student n i feel it is must for every c programmer. But im confused with what was written in first few lines : "the value is returned in EAX register." I mean no problem with basic types but how this statement fits fine for structures like: struct abc { int x; float y; }; struct abc fun(void) { struct abc x; x.x=0; x.y=1; return x; }
Spread wat u Know!
-
I must say "thnx" to the writer of article "Calling Conventions Demysified". It is such a good article, i mean im a student n i feel it is must for every c programmer. But im confused with what was written in first few lines : "the value is returned in EAX register." I mean no problem with basic types but how this statement fits fine for structures like: struct abc { int x; float y; }; struct abc fun(void) { struct abc x; x.x=0; x.y=1; return x; }
Spread wat u Know!
Returning things that don't fit into a register have a special rule in all calling conventions that use a register to return values. One possible solution some calling conventions use is that the caller reserves the memory for the return value and passes a pointer to it to the called function as a hidden parameter. So your example would be compiled like:
struct abc
{
int x;
float y;
};
void fun(struct abc *result)
{
struct abc x;
x.x=0;
x.y=1;
*result = x;
}An optimizing compiler might assign directly to result->x and result->y.