for, foreach identifier allowed in c throws error in d
John Colvin via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Jun 2 12:44:10 PDT 2014
On Monday, 2 June 2014 at 19:21:07 UTC, Logesh Pillay wrote:
> It is common in a recursive function to amend a global array
> using the function parameter to refer to the element eg
>
> int[10];
>
> void foo (int i) {
> foreach (x; 0 .. 9) {
> t[i] = x;
> foo ();
>
> C in a for loop allows use of t[i] directly as the iterating
> variable so you don't need the dummy variable x which has no
> real function.
>
> D does not. The error generated is "no identifier for
> declarator t[i]". For a long time, I thought that was specific
> to foreach but the same thing happens with for.
>
> It looks like an unnecessary restriction. Am I missing
> something?
works fine for me: http://dpaste.dzfl.pl/6ff9a3909fde
More information about the Digitalmars-d-learn
mailing list