Path: utzoo!mnetor!motto!andrew From: andrew@motto.UUCP (Andrew Walduck) Newsgroups: comp.lang.c Subject: passing structures Message-ID: <241@motto.UUCP> Date: 10 Oct 90 17:25:56 GMT Lines: 56 okay folks here goes... In the new ANSI standard, we can now pass (and return) a structure by value. Like so...(fragment follows) ----------------------------------------------------------------------- #include typedef struct complex { int real; int imag; } complex; complex add(complex, complex); /* function prototype for complex add */ int main(void) { complex result, a, b; a.real = 5; a.imag = 6; /* 5+6i */ b.real = 8; b.imag = 3; /* 8+3i */ result = add(a,b); /* should be 13+9i */ printf("result : %i+%ii\n", result.real, result.imag); } complex add(complex a, complex b) { complex result; result.real = a.real + b.real; result.imag = a.imag + b.imag; return result; } ----------------------------------------------------------------------- Now, that should work right?!! Now, here's the problem...what if I wanted to pass a constant structure to add! For example I wanted to add 5+8i to a: The call to add would look like this?? result = add(a,{5,8}); But this isn't supported by ANSII! There's no way to pass a structure as a parameter! It should be do-able, the prototype exists, so the types can be punned appropriately...any idea why it wasn't? No prior-art? Any idea how I can suggest this to the committee? Thanx Andrew Walduck ______________________________________________________________________ |andrew@motto.UUCP | I wasn't aware that Ada was useful - Henry Spencer|