From: ao950 AT FreeNet DOT Carleton DOT CA (Paul Derbyshire) Newsgroups: comp.os.msdos.djgpp Subject: Re: unused registers, realloc Date: 4 Aug 1997 04:29:24 GMT Organization: The National Capital FreeNet Lines: 24 Message-ID: <5s3lr4$od1@freenet-news.carleton.ca> References: Reply-To: ao950 AT FreeNet DOT Carleton DOT CA (Paul Derbyshire) NNTP-Posting-Host: freenet5.carleton.ca To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Shawn Hargreaves (Shawn AT talula DOT demon DOT co DOT uk) writes: > I'm not sure about the gcc malloc implementation, but I have in the past > used compilers that did move the block around (it took me forever to > work out why my code suddenly stopped working when I changed compiler!). > It's probably not a good plan to assume that it will stay in the same > place... It is always a good idea to do one of two things with stuff you intend to realloc: 1. Only use the one pointer to it; regenerate that pointer from realloc's return value. Or if this is impractical: 2. Double indirection. Malloc or calloc to a whatever * pointer. Assign this pointer's address to a whatever ** pointer. Use that pointer everywhere, using (*(*pointer)) to access data. When realloc is used, assign its return value into the whatever * pointer; thus what is pointed to by all copies of the doubly indirect pointer will be the new address. -- .*. Where feelings are concerned, answers are rarely simple [GeneDeWeese] -() < When I go to the theater, I always go straight to the "bag and mix" `*' bulk candy section...because variety is the spice of life... [me] Paul Derbyshire ao950 AT freenet DOT carleton DOT ca, http://chat.carleton.ca/~pderbysh