[Issue 6098] Static array corruption of data
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Jun 3 10:26:21 PDT 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6098
bearophile_hugs at eml.cc changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |bearophile_hugs at eml.cc
--- Comment #7 from bearophile_hugs at eml.cc 2011-06-03 10:21:52 PDT ---
(In reply to comment #4)
> Actually I can just dup manually instead of using the heap:
>
> return cycle(result.dup);
.dup creates a copy on the heap.
This is a safer implementation:
import std.stdio, std.math, std.algorithm, std.range;
auto makeSine() {
return cycle(map!q{ sin(a * PI) }(iota(0, 2, 0.2)));
}
void main() {
auto sineTable = makeSine();
writeln(take(sineTable, 10));
}
Regarding the unsafety of the version that uses a fixed sized array, I'd like
the compiler to warn better against such bugs.
--
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