Mail Archives: djgpp/1998/01/30/09:19:25
Eric Gillespie wrote:
>
> I am a beginner programmer, and have been writing a file lister program.
> In this program, I allocated an array (calloc) and later on, realloc'ed it.
> When later checking the array, contrary to what my documentation says, a
> large hunk of my array had been wiped! Does (should?) realloc behave the
> same under gcc as under Turbo C?
[SNIP]
> Excerpt from Turbo C Bible (C) 1989 The Waite Group p 138
>
> Description: ... The memory block of altered size may [possibly] not
> be located at the same address, but the contents of the
> new block (up to its old size) are guaranteed to be
> unchanged.
Hi Eric Gillespie,
You refer to Turbo-C and DJGPP in particular, but the behaviour quoted
above is actually guarantied by ANSI-C. So, if you've got a compiler
that claims to be ANSI-C compatible, it must behave in this way.
> For this reason, I cannot understand why my code is getting blitzed.
[MEGA SNIP]
Please read the reply by Rainer Temme, who has spotted a coding error
in your source code.
Stephan
(initiator of the campaign against grumpiness in c.l.c)
- Raw text -