Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!munnari.oz.au!goanna!ok From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) Newsgroups: comp.lang.c Subject: Re: passing structures Message-ID: <3959@goanna.cs.rmit.oz.au> Date: 12 Oct 90 01:24:05 GMT References: <241@motto.UUCP> Organization: Comp Sci, RMIT, Melbourne, Australia Lines: 37 In article <241@motto.UUCP>, andrew@motto.UUCP (Andrew Walduck) writes: > typedef struct { int real, imag; } complex; > complex add(complex, complex); /* function prototype for complex add */ ... { > complex result, a, b; > 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: > result = add(a,{5,8}); > But this isn't supported by ANSII! > Any idea how I can suggest this to the committee? It's *way* too late. The ANSI C standard is finished. But there is nothing at all to stop you writing { static complex k5_8 = {5,8}; result = add(a, k5_8); } Or you could do it the Fortran way: complex CMPLX(int real, int imag) { complex temp; temp.real = real, temp.imag = imag; return temp; } ... result = add(a, CMPLX(5, 8)); I prefer this approach myself, because then you can change the order (and number) of the fields in the struct without having to change the rest of your program, as long as the interface of CMPLX is not changed. With 'inline' functions (C++, some C compilers) this approach comes pretty close to what you want anyway. -- Fear most of all to be in error. -- Kierkegaard, quoting Socrates.