Iterating over 0..T.max
Steven Schveighoffer
schveiguy at yahoo.com
Thu Mar 10 05:01:06 PST 2011
On Thu, 10 Mar 2011 07:50:21 -0500, bearophile <bearophileHUGS at lycos.com>
wrote:
> Magnus Lie Hetland:
>
>> Derp. I didn't mean bool -- I was talking about byte. (Which should
>> make quite a bit more sense, given that I'm talking about a limit of
>> 256... :D)
>
> Please show a complete minimal program that gives you problem. (I have
> failed to reproduce your problem on Windows).
void main()
{
auto a = new ubyte[256];
foreach(ubyte i, ref e; a) e = i;
}
I think you should file this as a bug Magnus, I see no reason why this
should result in an infinite loop.
Probably the reason is because the compiler rewrites this as:
for(ubyte i = 0; i < a.length; i++)
where what it should do is:
for(size_t _i = 0; _i < a.length; _i++)
{
auto i = cast(ubyte) _i;
...
}
or just fail to compile if you use anything that can't hold a size_t as an
index type.
-Steve
More information about the Digitalmars-d-learn
mailing list