why ? why not... but why ?
Posted: Sun Sep 02, 2018 3:41 pm
If I compile this simple test program in OSDK :
the output is a total nonsense (n is changed just before the computation of stat[n] !)
Now, if I rename the n variable by nn, or if I remove the include line, everything works as expected.
Please, can you reproduce this ?
Where is my bug ?
Thank you very much for your help.
Code: Select all
#include <lib.h>
char rnd(char max);
int i,st;
char n=0;
char stat[4]={0,0,0,0};
void main()
{
for(i=0;i<10;i++) {
n=rnd(3);
printf(" n : %d ",n);
stat[n]=stat[n]+1;
printf(" n : %d ",n);
printf(" stat[n] : %d\n",stat[n]);
//printf("%d\n",rand());
}
printf("\n");
for(i=0;i<4;i++) printf("%d : %d\n",i,stat[i]);
}
char rnd(char max)
{
int i1,i2,i3;
i1=rand();
i2=32768/max;
i3=i1/i2;
return (char)i3;
}
Now, if I rename the n variable by nn, or if I remove the include line, everything works as expected.
Please, can you reproduce this ?
Where is my bug ?
Thank you very much for your help.