On Fri, 12 Dec 2008 02:47:42 +0300, BCS <[email protected]> wrote:
Reply to Denis,
On Fri, 12 Dec 2008 02:21:11 +0300, BCS <[email protected]> wrote:
Reply to Weed,
invariant()
{
// If I comment out next line compilation goes smoothly:
assert( Element.sizeof > 0 );
}
OTOH that assert is wrong. Element.sizeof will always return 8, the
size of an array reference. What you want is Element.length.
No, I don't think so. Don't confuse 'Element' with 'data'. Element is
a type, it doesn't have a length property. But it does have sizeof (an
example of Element is an 'int', which is 4 bytes long).
Oh, fud. I did get that wrong. I still think it's wrong as I'm not sure
anything has 0 sizeof and even then that should be static assert.
No, zero-sized arrays are allowed in D:
struct Palette
{
uint size;
ARGB[0] colors
}
Palette* createPalette(int numColors)
{
return cast(Palette*)GC.malloc(uint.sizeof + numColors * ARGB.sizeof);
}