Hola:
Just to clarify a bit (I'm still having the issue):
I'm not getting a compilation error but a runtime problem.
When I run it I should get:
....
ref date Line: 20051020 count: 9289
ref date Line: count: 9290
9290 9290 19690102 20051020 20051019 20051018 20051017
Returned: 9290
but I'm getting:
....
ref date Line: 20051020 count: 9289
ref date Line: count: 9290
9290 9290 0 0 0 0 0
ERROR: Last Date reference (0) is before test's end date(19901231),
dates file=/usr/local/etc/SPX_DAILY_DATES.asc
i=9290 count=9290
Returned: 0
The file is a linux file, with one date per line as: 20051020
I the same result on Athlon 32 bits and Intel/Xeon 32/64 bit machines.
Jairo Medina wrote:
Hola:
I hope you can help me with this program:
- it works OK if I compile it with: g++ main2.cpp -o main2
- it fails if I compile it with: g++ -O2 main2.cpp -o main2
(but if I enable the comment inside the "try", then the
program works.)
This happens in my FC4 box with g++ --version g++ (GCC) 4.0.2
20051125 (Red Hat 4.0.2-8)
On my FC3 boxes and my RH7.3 boxes the -O2 is OK.
Any help is appreciated
Thanks.
-------------------------------------------------------------------------
#include<string>
#include<iostream>
#include<fstream>
using namespace std;
int refDates[20000];
int getRefDates()
{
// JAM 2003-01-23 added search for SPX_DAILY_DATES.asc on /usr/local/etc
// get the reference date series
string filespec = "/usr/local/etc/SPX_DAILY_DATES.asc";
ifstream *ifile;
ifstream ifile1(filespec.c_str());
ifile = &ifile1;
if (!ifile->is_open())
{
cout << "ERROR: could not find varset date reference file at: "
<< filespec <<" or at: "<< endl;
return(-1);
}
cout<<"MainClass.cpp::getRefDates: Using "<<filespec<<endl;
string sDate;
int count = 0;
int i = 0;
for (i = 0; ;++i)
{
refDates[i] = 0;
std::getline(*ifile, sDate);
cout << "ref date Line: " << sDate <<" count: "<<count<< endl;
if (ifile->bad() || ifile->eof())
{
break;
}
//cout << "ref date Line: " << sDate <<" i:"<<i<<" count:
"<<count<<" refDates:"<<refDates[i]<<" prior refDate
="<<refDates[i-1]<< endl;
try
{
//char str[8];
//memcpy(str,sDate.c_str(),8);
//refDates[i] = (int)atoi(str);
refDates[i] = (int)atoi(sDate.c_str());
//cout<<count<<" "<<i<<" "<<refDates[i]<<" "<< atoi(sDate.c_str())<<"
"<< sDate.c_str()<<endl;
++count;
}
catch(...)
{
// error in date fetch
cout << "ERROR reading reference date from: "<<filespec<<" line
number: "<<count<< endl;
return(-1);
}
}
//cout<<"finished loading "<<count-1<<" "<<refDates[0]<<"
"<<refDates[count-1]<<" "<<refDates[count-2]<<endl;
int lastdate = refDates[count-1];
int firstdate = refDates[0];
refDates[count] = 0;
cout<<count<<" "<<i<<" "<<refDates[0]<<" "<<refDates[count-1]<<" "<<
refDates[count-2]<<" "<< refDates[count-3]<<" "<<refDates[count-4]<<endl;
//cout<<"first "<<testdef->Vars.GetNumber("StartDate")<<"
"<<(int)testdef->Vars.GetNumber("StartDate")<<" "<<firstdate<<endl;
if (firstdate > 20061031)
{
cout << "ERROR: First Date reference ("<<firstdate<<") is after
test's start date"<<20061031<<"), dates file="<< filespec << endl;
return(0);
}
//cout<<"last "<<testdef->Vars.GetNumber("EndDate")<<"
"<<(int)testdef->Vars.GetNumber("EndDate")<<" "<<lastdate<<endl;
if (lastdate < 19901231)
{
cout << "ERROR: Last Date reference ("<<lastdate<<") is before
test's end date("<<19901231<<"), dates file="<< filespec << endl;
cout<<" i="<<i<<" count="<<count<<endl;
return(0);
}
// MSE !!! add date error checks
ifile1.close();
// ok
return count;
}
int main()
{
cout<<" Returned: "<<getRefDates()<<endl;
}