pointers, functions, and uniform call syntax

Artur Skawina art.08.09 at gmail.com
Tue Sep 4 04:03:08 PDT 2012


On 09/03/12 23:19, Carl Sturtivant wrote:
> So I'm wondering if a language extension along the following lines would solve your problem, simply asking the compiler to use heap allocation when the variable is declared, e.g.
> 
>  @heap auto s = S(); //secretly allocated with new, but used as if local
> 
> where the compiler would know that s is valid, just as in a normal declaration. And the compiler would automatically deallocate the variable's heap storage when it goes out of scope. Otherwise the variable would behave like a normal local variable as far as inference of any kind made by the compiler in a wider context goes.

It could be part of the type (annotating the object/instance isn't really any
better than just using 'new'...), so

   struct S {
      new this(/*...*/) {/*...*/}
      /*...*/
   }

would let you skip the 'new' keyword. Might be useful when used with templates
(and a 'scope this(){}' ctor could ensure stack allocation). But as right now
struct allocations aren't properly supported yet (no custom allocators) adding
something like that shouldn't have high priority, even if it can be done w/o
breaking existing code (which does not use this feature).

artur


More information about the Digitalmars-d mailing list