www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1314] New: Dupping an empty array creates a null array

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1314

           Summary: Dupping an empty array creates a null array
           Product: D
           Version: 2.002
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: brunodomedeiros+bugz gmail.com


Dupping an empty array creates a null array:
----  ----
import std.stdio;

void main(char[][] args) {
        writefln("" is null);    // false
        writefln("".dup is null); // true
        writefln("".idup is null); // true
        writefln("".dup.ptr); // 0000
}


-- 
Jul 05 2007
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1314






Why is this a problem?


-- 
Jul 05 2007
prev sibling next sibling parent reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1314






I tought you had changed D some releases ago, such that empty arrays became
different than null arrays, wasn't that the case? (if not this is not a bug)


-- 
Jul 05 2007
parent Frits van Bommel <fvbommel REMwOVExCAPSs.nl> writes:
d-bugmail puremagic.com wrote:
 http://d.puremagic.com/issues/show_bug.cgi?id=1314
 

-------
 I tought you had changed D some releases ago, such that empty arrays became
 different than null arrays, wasn't that the case? (if not this is not a bug)
He only changed it so that setting .length to 0 no longer sets .ptr to null. He didn't change anything else regarding empty arrays AFAIK.
Jul 05 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1314







 Dupping an empty array creates a null array:
 ----  ----
 import std.stdio;
 
 void main(char[][] args) {
         writefln("" is null);    // false
         writefln("".dup is null); // true
         writefln("".idup is null); // true
         writefln("".dup.ptr); // 0000
 }
 
According to http://www.digitalmars.com/d/arrays.html shouldn't "".length be 1?
 String literals already have a 0 appended to them, so can be used directly
So shouldn't "".dup return a char array of length 1, containing the null character? Or is "" a special case that is interpreted as null? --
Jul 05 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1314






Similar to why an empty struct should still allocate a byte.


-- 
Jul 05 2007
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1314


brunodomedeiros+bugz gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID






 d-bugmail puremagic.com wrote:
 http://d.puremagic.com/issues/show_bug.cgi?id=1314
 

-------
 I tought you had changed D some releases ago, such that empty arrays became
 different than null arrays, wasn't that the case? (if not this is not a bug)
He only changed it so that setting .length to 0 no longer sets .ptr to null. He didn't change anything else regarding empty arrays AFAIK.
(and "".length should be 0, there is no doubt about that) --
Jul 06 2007