Re: Manually allocated structs

2014-07-27 Thread Domingo Alvarez Duarte via Digitalmars-d-learn
Hello again ! Anyone knows how to compile with gdc for different versions I could not find how gdc implements it if it does ? The proposed usage of "@property char[] buf()" although seems to work when compiled with dmd, segfaults when compiled with gdc: Code to test import std.stdio; i

Re: Manually allocated structs

2014-07-27 Thread Domingo Alvarez Duarte via Digitalmars-d-learn
On Sunday, 27 July 2014 at 12:49:01 UTC, Adam D. Ruppe wrote: I would do it something like this: struct test { size_t size; @property char[] buf() { return (_buf.ptr)[0 .. size]; } private char[0] _buf; } The buf property returns a slice that us

Re: Manually allocated structs

2014-07-27 Thread Adam D. Ruppe via Digitalmars-d-learn
I would do it something like this: struct test { size_t size; @property char[] buf() { return (_buf.ptr)[0 .. size]; } private char[0] _buf; } The buf property returns a slice that uses the size member to give you bounds checking, but uses the p

Manually allocated structs

2014-07-27 Thread Domingo Alvarez Duarte via Digitalmars-d-learn
Hello ! I have the code bellow that I want to manually allocate to use in runtime code, because I declared the payload "buf[1]" the compiler complains about index out of bounds then I managed to do this "*(&tmp.buf + tmp.used++) = c;" instead of "tmp.buf[tmp.used++] = c;" as is done usually i