Re: is strlen()'s read-4-bytes-ahead a standard?

看板FB_chat作者時間15年前 (2010/07/16 16:32), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串5/8 (看更多)
On Fri, 16 Jul 2010 09:41:23 +0200, "deeptech71@gmail.com" <deeptech71@gmail.com> wrote: >Xin LI wrote: >>On 2010/07/15 15:38, deeptech71@gmail.com 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. _______________________________________________ freebsd-chat@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-chat To unsubscribe, send any mail to "freebsd-chat-unsubscribe@freebsd.org"
文章代碼(AID): #1CG1a3oS (FB_chat)
討論串 (同標題文章)
文章代碼(AID): #1CG1a3oS (FB_chat)