Hello !

Based on a question about manually allocated structures with payload I found that a solution proposed seems to work when compiled with dmd but segfaults when compiled with gdc.

So my question is: Is this a bug on dmd, gdc or a bad idiom ?

---- code to see the problem
import std.stdio;
import core.stdc.stdlib;

void main()
{
        struct S
        {
                int size;
                char[0] _b;
                @property char[] buf() { return (_b.ptr)[0..size];}
        }
        
        int size = 12;
        S *s = cast(S*)malloc(S.sizeof + size);
        if(s !is null)
        {
                scope(exit) free(s);
                s.size = size;
                s.buf[0] = 'a';
                writeln(s.buf[0]);
        }
}

Reply via email to