my program was generating a "Segmentation fault" and i finally narrowed down where it was occuring. i have developed a simple program below that re-creates the seg fault.

the seg fault occurs in the testLoop on the line "if ( clock() < $min_calc )". it does not seem to happen if i comment out the "const long double" line and replace "$min_calc" with "GLOB_min_calc_time".

can someone please either let me know why this is happening or if i have other errors in my code that are causing this?

i using FreeBSD 5.3 and GCC 4.1

thanks so much!

Code:

#include <iostream>
#include <ctime>
bool testLoop ( int * const $calc_val );
long double GLOB_min_calc_time = 0;
int GLOB_min_secs = 5;
using namespace std;
int main( const int $argc, const char * $argv_arr[]){
int * $calc_val = new int;
*$calc_val = 2;
long double $clock_start = clock();
GLOB_min_calc_time = (long double)(clock() + (GLOB_min_secs * CLOCKS_PER_SEC)); //CLK_TCK
testLoop($calc_val);
long double $clock_end = clock();
cout << "calc_val: " << *$calc_val << endl;
cout << (long double)( $clock_end - $clock_start ) / (long double)CLOCKS_PER_SEC << " secs" << endl;
delete $calc_val;
return 0;
}
bool testLoop ( int * const $calc_val ){
const long double $min_calc = GLOB_min_calc_time;
*$calc_val = *$calc_val; //do some calculations
if ( clock() < $min_calc ){
testLoop($calc_val);
}
return true;
}