Re: C calling conventions: how to pass a struct parameter?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux