NO

Author Topic: help again  (Read 2598 times)

denise_amiga

  • Guest
help again
« on: January 23, 2007, 04:44:09 AM »
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?

Code: [Select]

#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.

Online AlexN

  • Global Moderator
  • Member
  • *****
  • Posts: 394
    • Alex's Link Sammlung
Re: help again
« Reply #1 on: January 23, 2007, 09:45:25 AM »
Quote from: "denise_amiga"


is this a compiler´s bug?

Code: [Select]

#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;

while (k <= 8190)
{
Flags[k] = 0;
k = k + prime;
}
}




It is a "little" bug in your program not in the compiler.

You have an array with 8190 members and you ask for k <= 8190. So you can point to then 8191th position and there are other variables stored witch are deleted if you meet this position. :?

When you use an optimizer this variables are kept in register and this error did not occur.
best regards
 Alex ;)

denise_amiga

  • Guest
help again
« Reply #2 on: January 23, 2007, 11:42:59 AM »
ok thx.