bs@alice.UucP (Bjarne Stroustrup) (09/06/86)
Karl W. Z. Heuer writes: > BMS-AT!stuart writes: > >I would like to see "structure constants" which would allow assignment to > >aggregate types. > > complex z; > > z = { a+1, exp(b) }; > > foo( (complex) { a, b } ); > > The problem, as your last example points out, is that the notation "{...}" > doesn't distinguish between different structure types. I suppose the cast > notation is workable, but kinda ugly. Or in C++: #include <complex.h> void foo(complex); void f() { double a,b; complex z; z = complex(a+1,exp(b)); foo( complex(a,b) ); } > >Of course any of these could be coded by assigning each member in turn. > > No, the last example requires assigning each member to a temporary, and then > passing that temporary as an argument. However, a clever compiler might use the calling stack as the temporary, but that is tricky (C++ doesn't attempt that feat).