X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f X-Recipient: djgpp AT delorie DOT com Date: Sat, 04 Jun 2011 17:24:46 +0300 From: Eli Zaretskii Subject: Re: Different memory allocations were to the same location In-reply-to: X-012-Sender: halo1 AT inter DOT net DOT il To: djgpp AT delorie DOT com Message-id: <83wrh1d68h.fsf@gnu.org> References: <83y61hd7xj DOT fsf AT gnu DOT org> Reply-To: djgpp AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk > From: Mok-Kong Shen > Date: Sat, 04 Jun 2011 15:53:56 +0200 > Bytes: 1681 > > Am 04.06.2011 15:48, schrieb Eli Zaretskii: > > > In generateintvec, you free the memory allocated by the previous call, > > so the same address is now available for reuse. Therefore calloc > > happily reuses it. > > > > Why is that a problem? > > But it should free the memory of that varialbe reprensented by the > formal parameter at the time of function call, shouldn't it? (In the > two calls uh was associated to different actual parameters.) C passes variables by value, so the original allocation is not affected. You must pass a pointer to a value be able to modify that value.