This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Classic C problems, need help!


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



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]