On Fri, 16 Jul 2010 09:41:23 +0200, "[email protected]" <[email protected]> wrote: >Xin LI wrote: >>On 2010/07/15 15:38, [email protected] wrote: >>> Some C implementations use the read-4-bytes-ahead technique to speed >>> up strlen(). Does the C standard state anything about strlen() being >>> allowed to read past the terminating zero? >> >> It's not 4-bytes-ahead, but read a whole (aligned) word at one time. >> >> I think C standard does not dictate in this detail. > > OK, can anyone confirm this?
The only text about strlen()'s behavior in my copy of the ISO/IEC 9899:1999 (E) standard is: | 7.21.6.3 The strlen function | | Synopsis | | 1 #include <string.h> | size_t strlen(const char *s); | | Description | | 2 The strlen function computes the length of the string pointed | to by s. | | Returns | | 3 The strlen function returns the number of characters that | precede the terminating null character. There is no reference to *how* this may be implemented, so you can safely assume that the usual "as if" rules of the C standard apply. The underlying code may read a single character at a time, a word at a time, or may even call system-specific kernel calls that do 'magic' behind the scenes to compute the string length. What _really_ matters, as far as the standard is concerned, is that you get a meaningful return value that matches the current length of the input string. _______________________________________________ [email protected] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-chat To unsubscribe, send any mail to "[email protected]"
