Article View: gnu.gcc.help
Article #42780Re: Simple C++ program bombs with G++ 2.6.3, not with 2.7.0
From: Jimen Ching
Date: Sat, 21 Oct 1995 00:00
Date: Sat, 21 Oct 1995 00:00
30 lines
1869 bytes
1869 bytes
Steve Johns (johns@adwyer.stx.com) wrote:
> The following simple program compiles and links with gcc 2.6.3 and
> libg++2.6.2, but core dumps at run time. I'm running on IRIX 5.2.
> On a different machine, with gcc 2.7.0, the program works fine.
Do you happen to know on which line it core dumps on? Try compile
with "-g" (debugging info), and go into any debugger. If you have
gdb (GNU debugger), try type 'backtrace' at the prompt. It will give
you the call stack sequence.
> Can anyone tell me why this might be?
>MyString::MyString(const MyString& source){ // copy constructor
> len = source.len;
> delete str_ptr;
> str_ptr = new char[len +1];
> strcpy(str_ptr, source.str_ptr);
>}
Ok, I'll try. Everything seems simple enough, except for this one.
This is a *copy* *constructor*. I.e. it is constructing a NEW object.
So, exactly what are you 'delete'ing? What does str_ptr point to that
you must delete it? On some systems, it's not a problem to delete
anything you want. I've even tried 'delete (void *)0' on a linux machine
and nothing happened. Maybe the IRIX is not so forgiving? Just
an observation, mind you. Can't tell what the problem is until I can
see the log from the debugger. Hope I gave you some ideas as to where
to start looking. Good luck...
--jc
--
Jimen Ching (WH6BRR) jching@aloha.com wh6brr@uhm.ampr.org
Technical Details
Message-ID:
<46abe4$5bh@news.aloha.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<JOHNS.95Oct19133756@adwyer.stx.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 11318c,f9cfce07b00d9958 X-Google-Attributes: gid11318c,public From: jching@aloha.com (Jimen Ching) Subject: Re: Simple C++ program bombs with G++ 2.6.3, not with 2.7.0 Date: 1995/10/21 Message-ID: <46abe4$5bh@news.aloha.com> X-Deja-AN: 117898353 distribution: local, usa references: <JOHNS.95Oct19133756@adwyer.stx.com> organization: FlexNet Inc, HAWAII newsgroups: gnu.gcc.help