On Thu, Jul 9, 2009 at 2:38 AM, Daniel Keep<[email protected]> wrote: > > You'd have to be mad to use it like that. > > struct S > { > int a; > private { size_t size; char[0] data; } > char[] message() { return data.ptr[0..length]; } > size_t length() { return size; } > > S* opCall(size_t size) > { > return cast(S*)((new ubyte[S.sizeof+size]).ptr); > } > } > > void main() > { > auto s = S(5); > s.message[] = "hello"; > writeln(s.message); > s.message[] = "world"; > writeln(s.message); > } >
You can't. The rest of my post explains that T[0].ptr is always null, for some reason. Currently I'm doing almost the same thing, though (cast(char*)(this + 1)[0 .. size]).
