Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > bug in XCode 2.4.1/gcc-4.0/x86_64 when declaring large number of ofstreams

bug in XCode 2.4.1/gcc-4.0/x86_64 when declaring large number of ofstreams
Thread Tools
cstricker
Fresh-Faced Recruit
Join Date: Mar 2007
Status: Offline
Reply With Quote
Mar 22, 2007, 12:32 PM
 
Dear all,

I want to open a large number of files (50-100) in a 64-bit C++ program on my mac Pro. However, 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
     
cstricker  (op)
Fresh-Faced Recruit
Join Date: Mar 2007
Status: Offline
Reply With Quote
Mar 22, 2007, 01:15 PM
 
I forgot to mention, that the code was compiling an running fine under the architecture ppc64 on a powermac G5.

chris
     
smitty825
Forum Regular
Join Date: Sep 2003
Location: San Diego
Status: Offline
Reply With Quote
Mar 24, 2007, 01:26 AM
 
That's a good question, and i really don't know the answer. (I'm stuck on a PowerPC machine here, and I haven't done any 64bit programming). If you don't get an answer here, you're best bet would be to describe the problem on one of Apple's developer mailing lists. I know you'll get a helpful response there...
     
arcticmac
Dedicated MacNNer
Join Date: Apr 2004
Status: Offline
Reply With Quote
Mar 25, 2007, 06:56 PM
 
why not just use fprintf() if you're just printing straight char stuff to files? I always found c++'s file streams or whatever they're called to be crazy anyhow. ('course, I only looked at 'em for like 30 minutes, but...)
     
mfbernstein
Senior User
Join Date: Mar 2007
Location: San Jose
Status: Offline
Reply With Quote
Mar 27, 2007, 08:44 PM
 
Is there a reason you're redeclaring the variable datafile1 in the example you gave, or is that just a typo? And where's the fopen() you're using? Mixing C++ iostreams and C stdio can have odd results. If you give us the failing testcase, it'll be a lot easier to see what the issue is.
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 01:10 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,