🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.help
Article #41468

Re: GCC 2.7.2: ofstream trashes memory - why?

#41468
From: Internet User ANA
Date: Thu, 11 Apr 1996 00:00
49 lines
1957 bytes
Urs Wuest <wuest@ana-ta.mtg.mt.com> wrote:
>-- 
>--------------------------------------------------------------------------
>                  Urs Wuest   \   Mettler-Toledo AG Analytical
>     wuest@ana-ta.mtg.mt.com   \   CH-8603 Schwerzenbach, SWITZERLAND
>--------------------------------------------------------------------------
>
>Hi!
>Consider following code sample:
>
>#include <fstream.h>
>
>class AClass {
>public:
>	AClass();
>	~AClass();
>};
>
>AClass::AClass () {	
>   cout << "AClass::AClass" << endl;
>}
>
>AClass::~AClass()  {
>   cout << "AClass::~AClass" << endl;
>}
>
>main() {
>AClass* object = new AClass;     		// Line 1
>cout << &(*object) << endl;			// Line 2
>
>ofstream out("file");				// Line 3
>// ofstream *out = new ofstream("file");	// Line 4
>// delete out					// Line 5
>
>cout << &(*object) << endl; 			// Line 6
>delete object;					// Line 7
>cout << "Bye" << endl;
>}
>
>When I compile and run this, I get a Segmentation Fault when I try to execute
>to (7). (6) returns a null address for the object itself, where as (2) is OK.
>If I replace (3) with (4)-(5), it compiles and runs as expected.
>What's wrong? Aren't both ofstreams allocated on the free store? If not, does
>it matter?
>
>Source code compiled under Solaris x86 2.4.
>
I am having the same problem can anybody help ?
bilar@ana-ta.mtg.mt.com
Technical Details
Message-ID: <4kibsl$f7@maine.mt.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <4jo3au$i8l@maine.mt.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11318c,e82a0275cba3df6b
X-Google-Attributes: gid11318c,public
From: Internet User ANA <iana@ana.mtg.mt.com>
Subject: Re: GCC 2.7.2: ofstream trashes memory - why?
Date: 1996/04/11
Message-ID: <4kibsl$f7@maine.mt.com>
X-Deja-AN: 146875838
references: <4jo3au$i8l@maine.mt.com>
content-type: text/plain; charset=us-ascii
organization: Mettler-Toledo AG, Switzerland
x-url: news:4jo3au$i8l@maine.mt.com
mime-version: 1.0
newsgroups: gnu.gcc.help
x-mailer: Mozilla 1.12 (X11; I; SunOS 5.4 sun4c)