void main() { struct S { ubyte[0] arr; } S s; assert(s.arr.ptr !is null); } s.arr.ptr should be the same as &s.
https://github.com/D-Programming-Language/dmd/pull/2888
Do you mean in this code: import core.stdc.stdlib, std.stdio; struct VariableLength(T) { size_t len; T[0] items; @property T[] data() inout pure nothrow { return (cast(T*)&items)[0 .. len]; } static typeof(this)* New(in size_t len) nothrow { auto vptr = cast(typeof(this)*)calloc(1, typeof(this).sizeof + T.sizeof * len); vptr.len = len; return vptr; } alias data this; } void main() { enum n = 0100; auto v = VariableLength!int.New(n); foreach (immutable i; 0 .. n) (*v)[i] = i * 10; foreach (immutable i; 0 .. n) writeln((*v)[i]); } The data() function will be written just like this? @property T[] data() inout pure nothrow { return items.ptr[0 .. len]; }
(In reply to comment #2) > Do you mean in this code: > > [snip] > > > The data() function will be written just like this? > > @property T[] data() inout pure nothrow { > return items.ptr[0 .. len]; > } Looks like you'll still need to cast away inout in that example, but yeah. Where a is a zero-length static array a.ptr -> &a
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/36c9b648a5701c4a9a73f3b1abf33e9a18e54839 Fix Issue 7175 - Zero-length static array .ptr is always null https://github.com/D-Programming-Language/dmd/commit/7652cfc7e279a2c23e4921bf52d46a6d663af253 Merge pull request #2888 from yebblies/issue7175 Issue 7175 - Zero-length static array .ptr is always null
Commit pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/3bf7718d82848f21b9e5562c96f3c7e8702c7ea7 Update message changed by fixing issue 7175
Commit pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/b7866eff1567e5dfdf0e28e99d6cb3515d273854 Fix bogus zero-length array test. Issue 7175 was about .ptr always giving null for a zero-length static array in a struct, despite the fact that the struct has size 1 and thus certainly a non-null address. The test case as modified by 36c9b64, however, checks that a free-standing zero-length static array on the stack has an address, which is quite a different scenario. From the spec, I don't see a reason why zero-sized objects should need any memory associated with them, so I am reluctant to pessimize LDC's codegen over this.