home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / std / c / 3017 < prev    next >
Encoding:
Internet Message Format  |  1992-11-17  |  1.2 KB

  1. Path: sparky!uunet!ogicse!emory!sol.ctr.columbia.edu!eff!world!ksr!jfw
  2. From: jfw@ksr.com (John F. Woods)
  3. Newsgroups: comp.std.c
  4. Subject: Re: strcmp() on a non-nil-terminated string
  5. Message-ID: <18866@ksr.com>
  6. Date: 17 Nov 92 17:38:22 GMT
  7. Article-I.D.: ksr.18866
  8. References: <1992Nov16.162313.3334@Urmel.Informatik.RWTH-Aachen.DE>
  9. Sender: news@ksr.com
  10. Lines: 22
  11.  
  12. berg@physik.tu-muenchen.de (Stephen R. van den Berg) writes:
  13. >char first[]="first";
  14. >char second[]={'s','e','c','o','n','d'};
  15. >main()
  16. >{ return!!strcmp(first,second);
  17. >}
  18. >--------------------------------------
  19. >Is this program allowed to behave undefined?
  20.  
  21. 4.1.1 Definitions of Terms "A string is a contiguous sequence of characters
  22. terminated by and including the first null character."
  23. 4.11.1 String Function Conventions "If an array is accessed beyond the end
  24. of an object, the behavior is undefined."
  25. 4.11.4.2 The strcmp Function "The strcmp function compares the string pointed
  26.                                                                ^^^^^^
  27. to by s1 to the string pointed to by s2."    (emphasis added)
  28.                 ^^^^^^
  29.  
  30. >You would expect a sane implementation to return with an exitcode of 1.
  31.  
  32. *I* would expect a sane programmer to read and understand the manual before
  33. plugging in the C compiler.
  34.