Pointer to string allows assigning int[]?

cal callumenator at gmail.com
Mon Nov 12 13:03:47 PST 2012


Is the following a bug?

import std.c.string, core.memory;

void* makeNew(T)()
{
     T t = T.init;
     void* ptr = GC.malloc(T.sizeof);
     memcpy(ptr, &t, T.sizeof);
     return ptr;
}

void main()
{
     alias string T;
     T* iptr = cast(T*)makeNew!(T);
     (*iptr) = [1,2,3]; // this is allowed
}


More information about the Digitalmars-d-learn mailing list