Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!caip!clyde!burl!ulysses!allegra!alice!bs From: bs@alice.UucP (Bjarne Stroustrup) Newsgroups: net.lang.c Subject: "structure constants" C++ Message-ID: <6022@alice.uUCp> Date: Fri, 5-Sep-86 21:35:33 EDT Article-I.D.: alice.6022 Posted: Fri Sep 5 21:35:33 1986 Date-Received: Sat, 6-Sep-86 20:24:37 EDT Organization: Bell Labs, Murray Hill Lines: 34 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 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).