[Issue 6098] Static array corruption of data
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Jun 3 13:00:26 PDT 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6098
kennytm at gmail.com changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |kennytm at gmail.com
--- Comment #8 from kennytm at gmail.com 2011-06-03 12:55:56 PDT ---
(In reply to comment #7)
> (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.
This will evaluate 'sin(a * PI)' N times, which totally goes against the reason
of making a sine table. You should 'array' the 'map' before 'cycle'-ing.
--
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