Minor issue - zero-length fixed size arrays in variable-sized structs..

Tim Matthews tim.matthews7 at gmail.com
Wed Jul 8 23:55:24 PDT 2009


Daniel Keep wrote:
> You'd have to be mad to use it like that.

I am mad.

> 
> 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);
> }

I don't know what you'd have to be to use it like that though ^ :)



More information about the Digitalmars-d mailing list