Can we just have struct inheritence already?
Vladimir Panteleev
thecybershadow.lists at gmail.com
Tue Jun 11 10:02:39 UTC 2019
On Tuesday, 11 June 2019 at 06:29:58 UTC, Walter Bright wrote:
> 1. How would an array of 0 size elements work, when the pointer
> past the end is the same as the pointer to the start?
>
> 2. How would you determine the dimension of an array of 0 size
> elements?
>
> sizeof(Array)/sizeof(Array[0])
>
> ? Oops!
But... 0-length arrays in D are already 0 bytes in size.
struct S
{
int a;
ubyte[0] b;
int c;
}
pragma(msg, S.tupleof.offsetof); // tuple(0LU, 4LU, 4LU)
pragma(msg, S.b.sizeof); // 0LU
We actually take advantage of this by declaring hashsets as
void[0][Key].
The same applies to two-dimensional 0-length arrays (T[0][0]),
which would make them an array with 0-size elements. I don't
think that's been a problem.
More information about the Digitalmars-d
mailing list