www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - dmd or linker bug

// Eratosthenes Sieve - Prime Number Calc

import std.c.stdio, std.date;

const int nloops=10000;
const int size=8191;

// *********** dmd V0.111 and dmd V0.110 bug: ************
// If the following array is changed to type 'bit', the
// last 'printf()' statement does not display any number.
// This bug reappears even if the array declaration is
// changed to 'D' style and also if '1' and '0' are
// changed to 'true' and 'false' respectively.
// Quickfix: If the array is moved inside the 'main()'
// function, the bug does not occur. Linker problem rather
// than dmd problem?
// *******************************************************

char    flagarr[size];

int     i, j, k, prime, pcount;
d_time  tstart, elapsed;

int main() {
printf("\nPerforming %d loops ...\n",nloops);

for (j=0; j<nloops; j++) {
pcount=0;  flagarr[]=1;
for (i=0; i<size; i++) {
if (flagarr[i]) {
pcount++;  prime=i+i+3;  k=i+prime;
while (k<size) { flagarr[k]=0;  k+=prime; }
} } }

printf("%g seconds (%d primes)\n",
Jan 20 2005