home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!hobbes!md
- From: md@sco.COM (Michael Davidson)
- Subject: Re: use of REALLOC under UNIX system
- Organization: The Santa Cruz Operation, Inc.
- Date: Tue, 12 Jan 1993 17:08:19 GMT
- Message-ID: <1993Jan12.170819.14049@sco.com>
- References: <C0pC48.G2z@compsci.liverpool.ac.uk> <1993Jan11.221607.9595@sco.com> <1993Jan12.063408.3848@ptcburp.ptcbu.oz.au>
- Sender: news@sco.com (News admin)
- Lines: 26
-
-
- michi@ptcburp.ptcbu.oz.au (Michael Henning) writes:
-
- >md@sco.COM (Michael Davidson) writes:
- >>- the only valid thing that you can pass to realloc()
- >>as it's first argument is the pointer returned from a successful
- >>call to malloc(), calloc() or realloc(). In other words, you can't
- >>RE-allocate something that you have never allocated in the first place!
-
- >No. Under ANSI C, realloc() can be passed a NULL pointer, in which case
- >it behaves as if malloc() was called. Initializing clast_str to NULL
- >will fix the problem, if libc conforms to ANSI C.
-
- Yes - you are correct about what ANSI allows, however there are still a
- lot of non-ANSI implementations around so I think that my advice was
- a little more general. In the specific example quoted by the original
- poster simply initialising clast_str to NULL isn't enough since passing
- a NULL pointer to strlen() is, as far as I know, *not* allowed by ANSI
- (and even if it were, it would, IMHO, be such bad programming practice
- that I would never advise anyone to do it).
-
- Anyway, I suspect from what the original poster was trying to do and
- the way in which they were approaching the problem, that what they *really*
- need is to get themselves a good book on C programming and pay special
- attention to the section on pointers....
-
-