C calling conventions: how to pass a struct parameter?

Eljay Love-Jensen eljay@adobe.com
Thu Apr 22 17:57:00 GMT 2004


Hi Cezar,

(Hey, "Cezar", cool name.)

This should work:

struct Foo { int a,b,c; };

void PrintFoo(struct Foo foo)
{
   printf("Foo:%d,%d,%d\n", foo.a, foo.b, foo.c);
}

That's a pass-by-value.

Here's pass-by-pointer:

void PrintFoo(struct Foo* foo)
{
   printf("Foo:%d,%d,%d\n", foo->a, foo->b, foo->c);
}

Here's pass-by-reference (C++ only):

void PrintFoo(Foo const& foo)
{
   printf("Foo:%d,%d,%d\n", foo.a, foo.b, foo.c);
}

Or am I misunderstanding your question?  Such as "what is the memory layout 
on the stack of the structure?", which depends on the aforementioned 
pass-by-???? method employed.

HTH,
--Eljay



More information about the Gcc-help mailing list