home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!pipex!unipalm!tim
- From: tim@unipalm.co.uk (Tim Goodwin)
- Subject: Re: realloc (again)
- Message-ID: <1993Jan12.123418.19090@unipalm.co.uk>
- Keywords: Realloc
- Organization: Unipalm Ltd., 216 Cambridge Science Park, Cambridge CB4 4WA, UK
- References: <C0pGL7.GqI@compsci.liverpool.ac.uk>
- Date: Tue, 12 Jan 1993 12:34:18 GMT
- Lines: 35
-
- scst81@csc.liv.ac.uk (Mr. I. Rowland) writes:
-
- >Following my last communication I developed another smaller program that
- > uses REALLOC in the same way as my other code:
-
- The same broken way, that is.
-
- Michael Davidson (md@sco.COM) and Michael Henning
- (michi@ptcburp.ptcbu.oz.au) between them explained that the first
- argument to realloc() must be:
-
- EITHER 1) a pointer previously obtained from malloc(), realloc(), or
- calloc();
-
- OR 2) the null pointer.
-
- [ You can only rely on case 2 working if your compiler is ANSI
- compliant; the following macro may be helpful for older compilers.
-
- #define REALLOC(p, l) ((p) ? realloc((p), (l)) : malloc(l))
- ]
-
- It is not meaningful to hand anything else (e.g. an uninitialised
- pointer variable) to realloc(). Why do you keep trying to do so?
-
- > What can
- > to be done to prevent it [a core dump] from happening?
-
- Use realloc() properly.
-
- > Again this program works on my Atari St using the Lattice C5 compiler.
-
- Only by coincidence, I'm afraid.
-
- Tim.
-