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

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!cs.utexas.edu!uwm.edu!linac!unixhub!ditka!eagercon!eagercon!eager
  3. From: eager@eagercon.com (Michael J. Eager)
  4. Subject: Re: Problem with string processing.
  5. Message-ID: <1993Jan11.060615.2180@eagercon.com>
  6. Sender: root@eagercon.com (Operator)
  7. Reply-To: eager@eagercon.com
  8. Organization: Eager Consulting
  9. References: <1idn10INNpvg@calamari.hi.com>
  10. Date: Mon, 11 Jan 1993 06:06:15 GMT
  11. Lines: 29
  12.  
  13. In article 1idn10INNpvg@calamari.hi.com, rogers@calamari.hi.com (Andrew Rogers) writes:
  14. >In article <Ts3TwB1w165w@wozzle.linet.org> alane@wozzle.linet.org (J. Alan Eldridge) writes:
  15. >>>         char tmp[2] = {0};
  16. >>>  
  17. >>>         *tmp = ch;
  18. >>>         strcat(str, tmp);
  19. >>
  20. >>tmp[0] has a 0 in it but tmp[1] is undefined. You are not creating
  21. >>a nul-terminated string here.
  22. >
  23. >tmp[1] most certainly does have a 0 in it; if the initialization list for
  24. >an array contains fewer elements than the array itself, then the remaining
  25. >array elements are initialized to 0.  Check the ANSI spec, or the relevant
  26. >section in K&R.
  27.  
  28. Well, the relevent section is 3.5.7, which says, in part "If an object that 
  29. has automatic storage duration is not initialized explicitly, its value is
  30. indeterminate."  Lacking a 'static' declaration and being within a function
  31. means that tmp has automatic storage.  Only the first element is initialized
  32. to zero, tmp[1] is undefined.
  33.  
  34. For static storage objects, all uninitialize elements get binary zero values.
  35.  
  36.  
  37. ---
  38. Michael J. Eager        Michael.Eager@eagercon.com
  39. Eager Consulting        (415) 325-8077 
  40. 1960 Park Boulevard, Palo Alto, CA 94306-1141
  41.  
  42.