Auto syntax revisited

Don Clugston dac at nospam.com.au
Wed Feb 22 01:22:18 PST 2006


Fredrik Olsson wrote:
> AgentOrange skrev:
>> In article <ops5bhg5ol23k2f5 at nrage.netwin.co.nz>, Regan Heath says...
>>
>>> On Mon, 20 Feb 2006 21:23:26 +0100, Fredrik Olsson 
>>> <peylow at gmail.com>  <snip>
>>> auto a = new A(); //heap alloc, 'a' is of type reference to 'A'
>>> auto a = A();     //stack alloc, destruct at scope exit, 'a' is of 
>>> type  reference to 'A'
>>>
>>> Regan
>>
>>
>> are we going to lose static opCall? yikes!
>>
> And the possibility of allowing non stack objects to automatically go 
> out of scope in the future without changing the syntax? I do not say 
> that it should be added now, all I say is that it would be good if the 
> syntax allowed for it. Ones we go 1.0 much of the syntax will pretty 
> much have to stay, so better be prepared :). A functionality restricted 
> by the compiler is easier to fix and causes less harm than a feature 
> restricted by the syntax.
> 
> Plus with: auto a = A();
> It is absolutely no way to just at a glance make sure with 100% sertenty 
> that a is not assigned the result of a function, instead of being 
> instantiated on the stack.

Does that matter? After all, a constructor is just a function. Clearly a 
new variable 'a' is being declared, it's type will be the return value 
of A(), and then A() needs to be called to initialise it.
Or have I missed something?



More information about the Digitalmars-d mailing list