issue with each specifically for x86

Matt Gamble gamblemj at gmail.com
Wed Mar 7 18:57:47 UTC 2018


This is a record for me with two 32bit vs 64bit issues in one 
day. Seems to be a problem with using "each" under 32bit which 
can be fixed by using foreach or switching to x64. Am I doing 
something wrong or is this the second bug I've found today?

Below is a silly case, that replicates an error. (i.e. I know I 
could use iota(0,9,2).array), but that does not demonstrate the 
potential bug and would not fix my actual program.)

import std.range;
import std.algorithm;
import std.stdio;

unittest
{
	auto a = new double[9];
	a[0] = 0;
	iota(1,a.length).each!(i => a[i] = a[i-1] + 2);
	writeln(a);
}

//x86, wrong, error
//[-nan, 2, 4, 6, 8, 10, 12, 14, 16]
//First-chance exception: std.format.FormatException Unterminated 
format specifier: "%" at 
C:\D\dmd2\windows\bin\..\..\src\phobos\std\format.d(1175)

//x64, correct
//[0, 2, 4, 6, 8, 10, 12, 14, 16]

unittest
{
	auto a = new double[9];
	a[0] = 0;
	foreach(i; 1..a.length) a[i] = a[i - 1] + 2;
	writeln(a);
}

//x86, correct
//[0, 2, 4, 6, 8, 10, 12, 14, 16]

//x64, correct
//[0, 2, 4, 6, 8, 10, 12, 14, 16]

This is windows 10, DMD v2.076.1



More information about the Digitalmars-d-learn mailing list