home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / std / c / 3024 < prev    next >
Encoding:
Text File  |  1992-11-17  |  1.6 KB  |  37 lines

  1. Newsgroups: comp.std.c
  2. Path: sparky!uunet!ferkel.ucsb.edu!taco!rock!stanford.edu!ames!haven.umd.edu!decuac!pa.dec.com!datum.nyo.dec.com!nntpd.lkg.dec.com!jit345.bad.jit.dec.com!diamond
  3. From: diamond@jit345.bad.jit.dec.com (Norman Diamond)
  4. Subject: Re: strcmp() on a non-nil-terminated string
  5. Message-ID: <1992Nov17.003044.10870@nntpd.lkg.dec.com>
  6. Sender: usenet@nntpd.lkg.dec.com (USENET News System)
  7. Reply-To: diamond@jit.dec.com (Norman Diamond)
  8. Organization: Digital Equipment Corporation Japan , Tokyo
  9. References: <1992Nov16.162313.3334@Urmel.Informatik.RWTH-Aachen.DE>
  10. Date: Tue, 17 Nov 1992 00:30:44 GMT
  11. Lines: 24
  12.  
  13. In article <1992Nov16.162313.3334@Urmel.Informatik.RWTH-Aachen.DE> berg@physik.tu-muenchen.de (Stephen R. van den Berg) writes:
  14. >#include <string.h>
  15. >char first[]="first";
  16. >char second[]={'s','e','c','o','n','d'};
  17. [...]
  18. >strcmp(first,second);
  19. >
  20. >Is this program allowed to behave undefined?
  21.  
  22. ANSI section 4.11.4, page 165 lines 5 to 7, say that the result depends on
  23. the sign of the difference between the first pair of characters that differ.
  24. This doesn't exactly say if the function can continue inspecting irrelevant
  25. characters up to the end of each string.
  26.  
  27. Section 4.11.4.2 implies that it might inspect each entire string.  But the
  28. implication is suspect -- because section 4.11.4.1 (memcmp) has similar
  29. language for the "Returns" paragraph in lines 16 to 17, forgetting the
  30. length limit in the "Description" paragraph in lines 13 to 14.
  31.  
  32. It might be wise to request an interpretation ruling.
  33. --
  34. Norman Diamond       diamond@jit081.enet.dec.com
  35. If this were the company's opinion, I wouldn't be allowed to post it.
  36. "It's been a lovely recession."
  37.