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

Steven Schveighoffer schveiguy at yahoo.com
Thu Jul 9 10:09:16 PDT 2009


On Thu, 09 Jul 2009 09:47:44 -0400, Jarrett Billingsley  
<jarrett.billingsley at gmail.com> wrote:

> On Thu, Jul 9, 2009 at 2:38 AM, Daniel Keep<daniel.keep.lists at gmail.com>  
> 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't.  The rest of my post explains that T[0].ptr is always null,
> for some reason.
>
> Currently I'm doing almost the same thing, though (cast(char*)(this +
> 1)[0 .. size]).

Would something like this work?

(&data)[0..length]

-Steve



More information about the Digitalmars-d mailing list