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





------- Comment #1 from bugzilla digitalmars.com  2007-07-05 13:31 -------
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





------- Comment #2 from brunodomedeiros+bugz gmail.com  2007-07-05 17:56 -------
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
 
 ------- Comment #2 from brunodomedeiros+bugz gmail.com  2007-07-05 17:56
-------
 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





------- Comment #4 from leikeze gmail.com  2007-07-05 18:32 -------
(In reply to comment #0)
 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





------- Comment #5 from chris dprogramming.com  2007-07-05 18:57 -------
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




------- Comment #6 from brunodomedeiros+bugz gmail.com  2007-07-06 04:03 -------
(In reply to comment #3)
 d-bugmail puremagic.com wrote:
 http://d.puremagic.com/issues/show_bug.cgi?id=1314
 
 ------- Comment #2 from brunodomedeiros+bugz gmail.com  2007-07-05 17:56
-------
 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.
You're right, I misunderstood bug #429 . (and "".length should be 0, there is no doubt about that) --
Jul 06 2007