[comp.lang.c] Summary: Realloc of function parameter problem.

SLORES@umiami.miami.edu (Stanislaw L. Olejniczak) (11/27/89)

Many thanks for the numerous answers I received to my question.  The
problem was, of course, the requirement that realloc receives as an
argument either a pointer previously returned by a malloc _or_ (char *)0,
while I passed to it a pointer initialized as char *p = "A string".  Some
respondent warned me that some compiler implementations get confused if
the argument is (char *)0.

Knowing all this I went back to TFM, including some for beginners, some for
intermediate, and some for advanced users, and looked again for a clear
reference to that fact.  I was able to piece the reason from various
section of K&R, but simply _nowhere_ could I find documentation for
realloc stating that fact.  This includes basic and intermediate manuals,
which went to great lengths to explain dynamic memory allocation.  

If someone would have a suggestion on a book or two that would go into
such matters in a fairly clear manner, I woulod appreciate the
recommendations.  Again, thanks for all your help and assistance.

----
Stan Olejniczak               Internet:         slores@umiami.miami.edu
University of Miami, FL USA   UUCP: (temp void) gould!umbio!solejni
SLORES@UMIAMI.BITNET          UUCP: (?)         umigw!gables!slores
Voice: (305) 547-6571         FAX: (305) 548-4612  
My opinions cannot possibly represent the views of anyone else!

gvr@brunix (George V. Reilly) (11/28/89)

In article <3772@umiami.miami.edu> SLORES@umiami.miami.edu (Stanislaw L. Olejniczak) writes:
< Many thanks for the numerous answers I received to my question.  The
< problem was, of course, the requirement that realloc receives as an
< argument either a pointer previously returned by a malloc _or_ (char *)0,
< while I passed to it a pointer initialized as char *p = "A string".  Some
< respondent warned me that some compiler implementations get confused if
< the argument is (char *)0.
< 
< Knowing all this I went back to TFM, including some for beginners, some for
< intermediate, and some for advanced users, and looked again for a clear
< reference to that fact.  I was able to piece the reason from various
< section of K&R, but simply _nowhere_ could I find documentation for
< realloc stating that fact.  This includes basic and intermediate manuals,
< which went to great lengths to explain dynamic memory allocation.  
< 
< If someone would have a suggestion on a book or two that would go into
< such matters in a fairly clear manner, I woulod appreciate the
< recommendations.  Again, thanks for all your help and assistance.

_C: A Reference Manual_, Second Edition, Samuel P. Harbison &
Guy L. Steele Jr, Prentice-Hall, 1987, ISBN 0-13-109802-0
gives a good explanation of how to use realloc().  It also gives a
fairly detailed explanation of how to use the rest of the standard
library.
------
George V. Reilly			gvr@cs.brown.edu
uunet!brunix!gvr   gvr@browncs.bitnet	Box 1910, Brown U, Prov, RI 02912