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

2009-07-08 Thread Jarrett Billingsley
I noticed in the spec on arrays that "A [fixed-size] array with a dimension of 0 is allowed, but no space is allocated for it. It's useful as the last member of a variable length struct.." This sounds like C99's "flexible array members," where a struct can have an array as its last element that is

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

2015-03-29 Thread Joakim via Digitalmars-d
On Wednesday, 8 July 2009 at 22:55:47 UTC, Jarrett Billingsley wrote: I noticed in the spec on arrays that "A [fixed-size] array with a dimension of 0 is allowed, but no space is allocated for it. It's useful as the last member of a variable length struct.." This sounds like C99's "flexible ar

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

2009-07-08 Thread Tim Matthews
Jarrett Billingsley wrote: I noticed in the spec on arrays that "A [fixed-size] array with a dimension of 0 is allowed, but no space is allocated for it. It's useful as the last member of a variable length struct.." ... It would be interesting if anyone has yet to find this useful. In c

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

2009-07-08 Thread Daniel Keep
You'd have to be mad to use it like that. 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); } }

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

2009-07-09 Thread Tim Matthews
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 uby

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

2009-07-09 Thread Jarrett Billingsley
On Thu, Jul 9, 2009 at 2:38 AM, Daniel Keep wrote: > > You'd have to be mad to use it like that. > > 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) >    {

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

2009-07-09 Thread Steven Schveighoffer
On Thu, 09 Jul 2009 09:47:44 -0400, Jarrett Billingsley wrote: On Thu, Jul 9, 2009 at 2:38 AM, Daniel Keep wrote: You'd have to be mad to use it like that. struct S {    int a;    private { size_t size; char[0] data; }    char[] message() { return data.ptr[0..length]; } ... You can

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

2009-07-09 Thread Jarrett Billingsley
On Thu, Jul 9, 2009 at 1:09 PM, Steven Schveighoffer wrote: > Would something like this work? > > (&data)[0..length] Nope; &data is a char[0]*, and slicing it will get you a char[0][]. Which is pretty useless :D

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

2009-07-10 Thread Steven Schveighoffer
On Thu, 09 Jul 2009 20:24:16 -0400, Jarrett Billingsley wrote: On Thu, Jul 9, 2009 at 1:09 PM, Steven Schveighoffer wrote: Would something like this work? (&data)[0..length] Nope; &data is a char[0]*, and slicing it will get you a char[0][]. Which is pretty useless :D d'oh! Yeah, th

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

2009-07-10 Thread Tim Matthews
Steven Schveighoffer wrote: Having the compiler do the right thing is a much better option :) -Steve Have you reported this issue as a bug/enhancement?