PDA

View Full Version : bug in XCode2.4.1/gcc 4.0/x86_64 when opening declaring large number of ofstreams?


cstricker
03-22-2007, 11:38 AM
Dear all,

I want to open a large number of files (50-100) in a 64-bit C++ program. When compiled under debug using the architecture i386 in Xcode, it runs fine. However, when the architecture flag is set to x86_64 and compilation is under relase, then I get a segmentation fault after the 18th fopen-statement.

the main program I use is

using namespace std;

int main (int argc, char * const argv[]) {
ofstream datafile1("file1");
cout<<endl<<"\n done file1..."<<endl;
ofstream datafile1("file2");
cout<<endl<<"\n done file2..."<<endl;
// and so on until
ofstream datafile1("file50");
cout<<endl<<"\n done file50..."<<endl;
return 0;
}

Anyone knows whether this is a known bug in gcc/Xcode??? It seems that it was a bug in older 32 bit gcc versions....

any hint is appreciated!

Chris

hayne
03-22-2007, 02:20 PM
It would be better to show us the actual code via copy & paste (what you have in your post is obviously written by hand as pseudo-code since it won't compile as it is - e.g. multiple variables all called 'datafile1').
And then tell us exactly where the segfault is.