www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Allocating classes on the stack

The following code works, but is it kosher?

#import std.c.stdlib, std.stdio;
#template stackAllocator() {



#T stackNew(T)(void* sp =alloca(T.classinfo.init.length) ) {


#class A {




#void main() {








C:\Users\llunesu\Desktop>dmd -run stack.d
{
this
newed
~this
}

(It's too bad I can't use "scope class A", since the stackNew is not 
allowed to return a scoped class)

L.
Nov 24 2006