help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: g++ usage of new generates a segmentation fault


From: Christophe Limbrée
Subject: Re: g++ usage of new generates a segmentation fault
Date: 11 Jul 2006 17:12:36 -0700
User-agent: G2/0.2

I didn't free all variables allocated with new because I thought that
the program termination woud free them for me. Obviously that could
cause my problem. As I am rewriting a c program, I am adding c++ code
step by step into my source code. c and c++ are mixed into my code. I
read somewhere that I could get conflict. Is it right?

Maurizio Loreti a écrit :

> "christophelimbree@hotmail.com" <christophelimbree@hotmail.com> writes:
>
> > I am currently rewriting a c program in c++. I work under LINUX 2.6
> > (DEBIAN). Sometimes I get a segmentation fault when I use "new". Could
> > it be because of the compiler "g++". There are still some c functions
> > like printf or open. Could it be the cause of my problem?
>
> as long as 1) all variables allocated with new are freed once and only
> once with delete; 2) all varables allocated with new [] are freed once
> and only once with delete []; 3) you don't shoot yourself in the foot
> with copy-ctors or assignment operators that do not handle correctly
> pointers allocated with new or new []; 4) there is nothing corrupting
> the arena like you writing in the wrong address (array index out of
> range etc.) --- the use of new should be safe and do not cause any
> segmentation fault.
>
> --
> Maurizio Loreti                         http://www.pd.infn.it/~loreti/mlo.html
> Dept. of Physics, Univ. of Padova, Italy              ROT13: ybergv@cq.vasa.vg



reply via email to

[Prev in Thread] Current Thread [Next in Thread]