This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: C++ SEGMENT fault and vtable issu
- From: Arthur Schwarz <aschwarz1309 at att dot net>
- To: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Thu, 18 Oct 2012 18:44:38 -0700 (PDT)
- Subject: Re: C++ SEGMENT fault and vtable issu
Hi Jonathan;
Because I'm a wise old critter (or serendipity struck -
choice is yours), I think that I found the cause of my
difficulties.
1: I constructed my own 'new' and 'delete' operators.
2: I am constructing a list processor with a list header
which has a count of references to the itself.
3: When the reference count is zero, I delete the header
and the list contents.
I had expected that the C++ kernel would not participate
in this. However, what appears to be happening is that when
the C++ kernel sees a delete, the object 'vptr' is removed.
This is not the behavior I want. In particular I would like
to:
1: Retain the C++ 'delete' operator.
2: Remove the 'vptr' only when I want.
Creating a method for a delete seems unnatural and needlessly
tedious for someone using the software. Do I have any control
over when the 'vptr' is removed? Alternatively, is there a
non-gcc dependent way of reinserting the 'vptr' into a deleted
(but not yet deleted) class object?
I can't actually verify that my analysis is correct. The IDE
does not display the 'vptr' for pointers and only provides
the 'vptr' for references when the reference is highlighted,
not when the variables in scope are displayed. I don't know
if my guess is correct.
And of course, thanks.
art
----- Original Message ---- From: Jonathan Wakely <jwakely.gcc@gmail.com> To:
Arthur Schwarz <aschwarz1309@att.net> Cc: gcc-help@gcc.gnu.org Sent: Sun,
October 14, 2012 4:19:13 PM Subject: Re: C++ SEGMENT fault and vtable issues On
14 October 2012 20:29, Arthur Schwarz wrote: > Product Version = NetBeans IDE
7.2 (Build 201207171143) > Operating System = Windows 7 version 6.1 running on
x86 > Java; VM; Vendor = 1.7.0_03 > Runtime = Java HotSpot(TM) Client VM
22.1-b02 I doubt your IDE or JVM is relevant. > Cygwin gcc 4.5.3 >
gdb 4.5.3 > > I have a problem with my C++ application. I have tried to find
what is wrong in > my code and am unsuccessful, and amm hping that you can
identify the issue. > > The code fails (for different reasons) in two locations:
> [code] > SlipHeader* oldHeader; > delete oldHeader; // SEGMENT fault;
custom defined delete > > SlipHeader* header; > stringstream pretty; >
pretty << header->toString(); // call to pure virtual function > [/code]
Clearly this isn't the real code, because oldHeader and header are never
initialized. If you show the real code, preferably reduced to the minimum
necessary to demonstrate the problem, then someone might be able to suggest
where to look for the bug. It sounds like using an object after it's been
deleted or some other memory/lifetime issue. On GNU/Linux I'd use valgrind to
check for that sort of problem. There are tools to do a similar job on Windows,
but the only one I've tried is far inferior to valgrind and isn't free (as in
beer or freedom) so I won't recommend it.