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

Steven Schveighoffer schveiguy at yahoo.com
Fri Jul 10 06:29:25 PDT 2009


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

> On Thu, Jul 9, 2009 at 1:09 PM, Steven  
> Schveighoffer<schveiguy at yahoo.com> 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, the only improvement I can make on your code then is:

(cast(char*)&data)[0..length];

Or the more general:

(cast(typeof(data[0])*)&data)[0..length]

Which still involves a cast.  Crappy.  Having the compiler do the right  
thing is a much better option :)

-Steve



More information about the Digitalmars-d mailing list