home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / c / 19580 < prev    next >
Encoding:
Text File  |  1993-01-12  |  1.4 KB  |  47 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!pipex!unipalm!tim
  3. From: tim@unipalm.co.uk (Tim Goodwin)
  4. Subject: Re: realloc (again)
  5. Message-ID: <1993Jan12.123418.19090@unipalm.co.uk>
  6. Keywords: Realloc
  7. Organization: Unipalm Ltd., 216 Cambridge Science Park, Cambridge CB4 4WA, UK
  8. References: <C0pGL7.GqI@compsci.liverpool.ac.uk>
  9. Date: Tue, 12 Jan 1993 12:34:18 GMT
  10. Lines: 35
  11.  
  12. scst81@csc.liv.ac.uk (Mr. I. Rowland) writes:
  13.  
  14. >Following my last communication I developed another smaller program that
  15. >  uses REALLOC in the same way as my other code:
  16.  
  17. The same broken way, that is.
  18.  
  19. Michael Davidson (md@sco.COM) and Michael Henning
  20. (michi@ptcburp.ptcbu.oz.au) between them explained that the first
  21. argument to realloc() must be:
  22.  
  23. EITHER 1) a pointer previously obtained from malloc(), realloc(), or
  24. calloc();
  25.  
  26. OR 2) the null pointer.
  27.  
  28. [ You can only rely on case 2 working if your compiler is ANSI
  29. compliant; the following macro may be helpful for older compilers.
  30.  
  31.     #define REALLOC(p, l) ((p) ? realloc((p), (l)) : malloc(l))
  32. ]
  33.  
  34. It is not meaningful to hand anything else (e.g. an uninitialised
  35. pointer variable) to realloc().  Why do you keep trying to do so?
  36.  
  37. >                                                                What can
  38. >  to be done to prevent it [a core dump] from happening?
  39.  
  40. Use realloc() properly.
  41.  
  42. >  Again this program works on my Atari St using the Lattice C5 compiler.
  43.  
  44. Only by coincidence, I'm afraid.
  45.  
  46. Tim.
  47.