This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Classic C problems, need help!
- From: John Love-Jensen <eljay at adobe dot com>
- To: Glover George <dime at gulfsales dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Fri, 03 May 2002 12:49:57 -0500
- Subject: Re: Classic C problems, need help!
- References: <000001c1f2c9$ee002620$0300a8c0@yellow>
Hi Dime,
What you are running into is the concept known as OWNERSHIP. I put
OWNERSHIP in capitals because it is a very important C/C++ detail to get
right -- otherwise memory leaks or dangling pointers, then Bad Things Happen
shortly thereafter. Aside: Java gets around the OWNERSHIP problem by having
garbage collection, pass-by-value for POD and pass-by-reference for UDT.
When you pass the char* to the other routine, does it's contract say that it
is taking OWNERSHIP of that string? And thus, is responsible to destruct
it, when appropriate.
Or does that other routine merely borrow that string for whatever
purposes... input only? output only? input/output (aka update)? utility
or functor (more so for C++ than C)?
Without known the contract that the routine is operating under, I cannot
tell you your proper course of action.
--Eljay