A funny thing happened to me this morning. The following code caused my
computer to crash when compiled under TC++3.0, BC++4.0 and BC++4.5:
#define FFT_SIZE 4096
void main(void)
{
float input_waveform[FFT_SIZE];
int loop;
int decoded_frequency;
float dummy;
int encoded_frequency = 0;
printf("program started\n");
while(encoded_frequency != -1)
{
printf("Enter input Frequency (Hz):");
scanf("%d",&encoded_frequency);
for(loop=0; loop < FFT_SIZE; loop++)
{
dummy = 2 * PI * encoded_frequency * loop / 8000.0;
input_waveform[loop] = sin(dummy);
/*printf("Entry:%d\tDummy:%f\tValue:%f\n",loop,dummy,input_waveform[loop]);*/
}
real_han(input_waveform, FFT_SIZE);
decoded_frequency = ctcss_decode(input_waveform);
decoded_frequency *= 8000 / (float)(FFT_SIZE);
printf("Entered Frequency: %dHz\n",encoded_frequency);
printf("Detected Frequency: %dHz\n",decoded_frequency);
/*delay(5000);*/
}
}
However when I changed the input_waveform definition to a static (shifting
it from the stack to global memory space IMHO) the problem was fixed.
Obviously it is crazy to put 4k arrays on the stack on a PC, but I was
under the impression that my friendly borland compiler would tell me that it
did not have the space to hold this array, instead of just crashing.
Can anyone shed some light on this? Just for the record I tried compiling
the code under all available memory models.
Thanks in advance,
Josh.