DMD 1.035 and 2.019 releases

Robert Fraser fraserofthenight at gmail.com
Wed Sep 3 22:21:43 PDT 2008


bobef wrote:
> Walter Bright Wrote:
> 
>> bearophile wrote:
>>> Walter Bright:
>>>> If there's any constructor defined for S, then S(args) is a
>>>> constructor call. If there's any opCall defined for S, then S(args)
>>>> is an opCall call. Otherwise, it's a struct literal.
>>> I haven't tried that in real code, so I can't be sure, but while it
>>> may work for the compiler, it sounds a bit too much complex for the
>>> person that later reads the code. Too many alternative possibilities
>>> may make the code more complex to follow.
>>>
>>> To reduce such ambiguity (ambiguity for the person, not for the
>>> compiler) may be to change the syntax of struct literals...
>> I disagree, I think just the reverse. The S(args) syntax means that it's 
>> entirely up to the struct designer to say how it should work. The user 
>> needn't know or care, and the struct designer can change the design 
>> without affecting user code.
>>
> 
> And why not "new S(args)" to call the constructor (which is natural so far) and "S(args)" to work as it does now?

How would you distinguish between allocating the struct on the heap and 
on the stack? "new" anything does heap allocation and returns a 
pointer/reference, so it would be inconsistent if it did stack 
allocation for structs (plus, then you'd have to manually allocate the 
heap memory & copy the struct over... ew).

class C { }
struct S { }

int* i = new int; // Heap allocates
C c = new C; // Heap allocates
S* s = new S; // Heap allocates


More information about the Digitalmars-d-announce mailing list