the original´s source is from freebasic examples. the problem is, when compile without optimization, the program never end.
with optimization the program run well.
is this a compiler´s bug?
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdio.h>
#define INTERATIONS 10000
int main(int argc, char *argv[])
{
int Flags[8190];
int iter;
int count;
int prime;
int k;
int i;
long x;
x = GetTickCount();
for (iter = 0; iter < INTERATIONS; iter++)
{
count = 0;
for (i = 0; i < 8190; i++)
Flags[i] = 1;
for (i = 0; i < 8190; i++)
{
if (Flags[i] == 1)
{
prime = (i * 2) + 3;
k = i + prime;
while (k <= 8190)
{
Flags[k] = 0;
k = k + prime;
}
count++;
}
}
}
x = GetTickCount() - x;
printf("msecs taken:%d\ncount:%d\n", x, count);
return 0;
}
sorry for my english.