July 21, 2005 zero size static array behaviour "incongruous" | ||||
---|---|---|---|---|
| ||||
The behaviour of static and dynamic arrays is inconsistent here: import std.stdio; void main() { int[0] s; int[ ] p = new int[0]; writefln("%d %x",p.length,p.ptr); writefln("%d %x",s.length,s.ptr); } [Output] 0 0 0 12ff28 I would suggest that "int[0] s;" be an error, as it's pretty meaningless.. Except template programmers would likely be a little annoyed with that. I would suggest that "int[0] s;" have a null data pointer (as the dynamic one does), but I believe they're implemented in such a way that there is no such data pointer. I hope Walter can see a good solution to this. Ideally they should behave the same I feel. Regan |
July 21, 2005 Re: zero size static array behaviour "incongruous" | ||||
---|---|---|---|---|
| ||||
Posted in reply to Regan Heath | On Thu, 21 Jul 2005 16:10:23 +1200, Regan Heath <regan@netwin.co.nz> wrote:
> The behaviour of static and dynamic arrays is inconsistent here:
>
> import std.stdio;
>
> void main()
> {
> int[0] s;
> int[ ] p = new int[0];
>
> writefln("%d %x",p.length,p.ptr);
> writefln("%d %x",s.length,s.ptr);
> }
>
> [Output]
> 0 0
> 0 12ff28
>
> I would suggest that "int[0] s;" be an error, as it's pretty meaningless.. Except template programmers would likely be a little annoyed with that.
>
> I would suggest that "int[0] s;" have a null data pointer (as the dynamic one does), but I believe they're implemented in such a way that there is no such data pointer.
>
> I hope Walter can see a good solution to this. Ideally they should behave the same I feel.
I suspect the solution is to cause "new int[0]" to allocate a zero length item on the heap.
Regan
|
Copyright © 1999-2021 by the D Language Foundation