samuraicrow:
"AFAIK structures cannot be passed by value and must be passed by reference"
Well, I was looking at this already and have written a test program that works. Did I compile this wrong?
gcc -Wall testbyval.c -o testbyval
The code is
/* test passing structures by value - why does this work? */
#include
struct coord {
int x;
int y;
};
struct coord testbyvalue(struct coord o)
{
o.x++;
o.y++;
return o;
}
int main(void)
{
struct coord c1 = {1,2};
struct coord c2 = testbyvalue(c1);
printf("c1 = {%d,%d}\nc2 = {%d,%d}\n}", c1.x, c1.y, c2.x, c2.y);
return 0;
}