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

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