Bug on dmd or gdc ?
Domingo Alvarez Duarte via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Jul 27 19:02:41 PDT 2014
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]);
}
}
More information about the Digitalmars-d-learn
mailing list