[Issue 1906] New: foreach cannot use index with large arrays

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Mar 11 05:20:10 PDT 2008


http://d.puremagic.com/issues/show_bug.cgi?id=1906

           Summary: foreach cannot use index with large arrays
           Product: D
           Version: unspecified
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: jlquinn at optonline.net


In D, array length is specified to be size_t, which allows for arrays up to the
size of memory.  However, the indexing form of foreach only permits an int or
uint as the index variable.  This will likely result in a silent bug used on an
array w/ more than 4G elements in a 64 bit environment.  For example:

char[] x;
x.length = 0x2_0000_0000L;
// fill the array
foreach (int i, char c; x)
  do_something(i, c);

foreach should be able to support a size_t in the index variable location.


-- 



More information about the Digitalmars-d-bugs mailing list