home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / c / 12762 < prev    next >
Encoding:
Internet Message Format  |  1992-08-25  |  2.0 KB

  1. Xref: sparky comp.lang.c:12762 comp.std.c:2510
  2. Newsgroups: comp.lang.c,comp.std.c
  3. Path: sparky!uunet!uunet.ca!wildcan!sq!msb
  4. From: msb@sq.sq.com (Mark Brader)
  5. Subject: Re: strcpy implementation question
  6. Message-ID: <1992Aug25.170433.10110@sq.sq.com>
  7. Organization: SoftQuad Inc., Toronto, Canada
  8. References: <1992Aug22.132132.13813@iecc.cambridge.ma.us> <1992Aug23.003930.9918@saaf.se> <1992Aug25.063134.18645@netfs.dnd.ca>
  9. Date: Tue, 25 Aug 92 17:04:33 GMT
  10. Lines: 35
  11.  
  12. In articles whose Distribution lines are invalid (don't do that!),
  13. John R. Levine (johnl@iecc.cambridge.ma.us) writes:
  14.  
  15. > > In my copy of the C standard, section 4.1.1 says "a string is a contiguous
  16. > > sequence of characters terminated by and including the first null
  17. > > character."  Section 4.11.2.3 says "The strcpy function copies the string
  18. > > pointed to by s2 (including the terminating null character) into the array
  19. > > pointed to by s1."
  20. > > 
  21. > > But it doesn't say "(including the terminating null character and any other
  22. > > garbage convenient for the compiler implementer)".  You have to stop at the
  23. > > null byte.
  24.  
  25. And Bob Balkwill (balkwill@ncs.dnd.ca) replies:
  26.  
  27. > Sorry - but one cannot assume more than the C std declares.  Maybe old
  28. > ill-advised code will break, but what happens after the null byte is up for
  29. > grabs. ...
  30.  
  31. However, one can assume *as much* as the standard declares.
  32.  
  33. As I said in email to the original poster, the standard also does not say
  34. that strcpy() doesn't write "Mark is an idiot\n" to stdout.  It doesn't have
  35. to!  [Er, I mean that the standard doesn't have to say that, not that
  36. strcpy() doesn't have to write that. :-)]  The descriptions in part 4 of
  37. the standard tell *everything* that the functions are supposed to do.
  38.  
  39. The string is terminated by the null character, and copying any more is
  40. an error.  John is right.  In my educated opinion.
  41. -- 
  42. Mark Brader            "A clarification is not to make oneself clear.
  43. SoftQuad Inc., Toronto         It is to PUT oneself IN the clear."
  44. utzoo!sq!msb, msb@sq.com        -- Lynn & Jay, "Yes, Prime Minister"
  45.  
  46. This article is in the public domain.
  47.