How about Go's &Struct instead of new?

Bill Baxter wbaxter at gmail.com
Thu Nov 12 17:44:09 PST 2009


On Thu, Nov 12, 2009 at 5:32 PM, xx <xx at xx.com> wrote:
>> In Go (from what I understand), a struct is stack allocated with
>>    x := Struct();
>> and heap allocated with
>>    x := &Struct();
>
> It's a nice trick, but I don't find it intuitive. Getting address of an object (re)allocates it? Literal that has different address each time?

I look at it more as taking the address of the type, which is
currently meaningless, then passing that some constructor args.

But good point... the syntax is ambiguous with taking the address of
the constructed value literal.
I guess that would force you to add a new precendence rule.  So to
actually take the address you'd need &(Struct()).

I like it less now.

--bb



More information about the Digitalmars-d mailing list