[Issue 3825] New: A bug-prone situation with AAs
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Feb 18 12:26:52 PST 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3825
Summary: A bug-prone situation with AAs
Product: D
Version: 2.040
Platform: x86
OS/Version: Windows
Status: NEW
Severity: normal
Priority: P2
Component: druntime
AssignedTo: sean at invisibleduck.org
ReportedBy: bearophile_hugs at eml.cc
--- Comment #0 from bearophile_hugs at eml.cc 2010-02-18 12:26:51 PST ---
import std.stdio;
void main() {
string[] words = ["how", "are", "you", "are"];
int[string] aa1;
foreach (w; words)
aa1[w] = ((w in aa1) ? (aa1[w] + 1) : 2);
writeln(aa1); // Prints: [how:1,you:1,are:2]
int[string] aa2;
foreach (w; words)
if (w in aa2)
aa2[w]++;
else
aa2[w] = 2;
writeln(aa2); // Prints: [how:2,you:2,are:3]
}
This can be a source of bugs in programs. I don't know if there are ways to
help the programmer avoid this bug.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list