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

看板FB_chat作者時間15年前 (2010/07/16 16:32), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串4/8 (看更多)
Xin LI <delphij@delphij.net> writes: > deeptech71@gmail.com writes: > > 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. My guess is that it invokes undefined behavior, but it doesn't matter in practice, because as long as you only read one aligned word at a time, and as long as the pointer you got is valid and points to a properly terminated string, you might read trash (which is expected), but you will never read unmapped memory. DES --=20 Dag-Erling Sm=C3=B8rgrav - des@des.no _______________________________________________ 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): #1CG1a2wC (FB_chat)
討論串 (同標題文章)
文章代碼(AID): #1CG1a2wC (FB_chat)