Newsgroups: comp.lang.c Path: utzoo!henry From: henry@zoo.toronto.edu (Henry Spencer) Subject: Re: passing structures Message-ID: <1990Oct11.162737.11332@zoo.toronto.edu> Organization: U of Toronto Zoology References: <241@motto.UUCP> Date: Thu, 11 Oct 90 16:27:37 GMT In article <241@motto.UUCP> andrew@motto.UUCP (Andrew Walduck) writes: >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? No prior art and limited need. You can pass structures as parameters all you want, but there is no way to compose a structure constant "on the fly". You have to do something like this: { complex c58 = { 5, 8 }; ... result = add(a, c58); There are various subtle problems with "structure constant" schemes; it is not as simple as it looks, especially when unions enter the picture. It's not unsolvable, mind you, but it's not as trivial as you seem to think. Given this, and the near-total lack of experience with it, X3J11 decided not to include it in ANSI C. >Any idea how I can suggest this to the committee? Implement it in a compiler, have it used by yourself and others for a few years, and propose it when ANSI C comes up for revision. You can't propose it now; nobody is listening. The odds of proposing it successfully at revision time go way up if you have an implementation and good experience to report. Actually, I believe there already are implementations that do this (in various ways), so it may be just a matter of adding your voice -- when the time comes -- to the folks saying "we've used this, it works". -- Imagine life with OS/360 the standard | Henry Spencer at U of Toronto Zoology operating system. Now think about X. | henry@zoo.toronto.edu utzoo!henry