Bug 1314 – Dupping an empty array creates a null array

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2007-07-05T06:09:00Z
Last change time
2015-06-09T01:04:59Z
Keywords
wrong-code
Assigned to
bugzilla
Creator
bruno.do.medeiros+deebugz

Comments

Comment #0 by bruno.do.medeiros+deebugz — 2007-07-05T06:09:41Z
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 }
Comment #1 by bugzilla — 2007-07-05T13:31:45Z
Why is this a problem?
Comment #2 by bruno.do.medeiros+deebugz — 2007-07-05T17:56:39Z
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)
Comment #3 by fvbommel — 2007-07-05T18:10:25Z
[email protected] wrote: > http://d.puremagic.com/issues/show_bug.cgi?id=1314 > > ------- Comment #2 from [email protected] 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.
Comment #4 by leikeze — 2007-07-05T18:32:53Z
(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?
Comment #5 by chris — 2007-07-05T18:57:51Z
Similar to why an empty struct should still allocate a byte.
Comment #6 by bruno.do.medeiros+deebugz — 2007-07-06T04:03:40Z
(In reply to comment #3) > [email protected] wrote: > > http://d.puremagic.com/issues/show_bug.cgi?id=1314 > > > > ------- Comment #2 from [email protected] 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)