From owner-freebsd-chat@FreeBSD.ORG Fri Jul 16 08:30:50 2010 Return-Path: Delivered-To: freebsd-chat@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 8ADAF106566B for ; Fri, 16 Jul 2010 08:30:50 +0000 (UTC) (envelope-from keramida@ceid.upatras.gr) Received: from igloo.linux.gr (igloo.linux.gr [62.1.205.36]) by mx1.freebsd.org (Postfix) with ESMTP id CC85D8FC14 for ; Fri, 16 Jul 2010 08:30:49 +0000 (UTC) X-Spam-Status: No X-Hellug-MailScanner-From: keramida@ceid.upatras.gr X-Hellug-MailScanner-SpamCheck: not spam, SpamAssassin (not cached, score=-0.2, required 5, autolearn=not spam, ALL_TRUSTED -1.00, BAYES_50 0.80) X-Hellug-MailScanner: Found to be clean X-Hellug-MailScanner-ID: o6G8JXvS029572 Received: from kobe.laptop (188.4.25.184.dsl.dyn.forthnet.gr [188.4.25.184]) (authenticated bits=128) by igloo.linux.gr (8.14.3/8.14.3/Debian-9.1) with ESMTP id o6G8JXvS029572 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 16 Jul 2010 11:19:39 +0300 Received: from kobe.laptop (kobe.laptop [127.0.0.1]) by kobe.laptop (8.14.4/8.14.4) with ESMTP id o6G8JSMc025891 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 16 Jul 2010 11:19:28 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Received: (from keramida@localhost) by kobe.laptop (8.14.4/8.14.4/Submit) id o6G8JRDT025884; Fri, 16 Jul 2010 11:19:27 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) From: Giorgos Keramidas To: deeptech71@gmail.com References: Date: Fri, 16 Jul 2010 11:19:27 +0300 In-Reply-To: (deeptech's message of "Fri, 16 Jul 2010 09:41:23 +0200") Message-ID: <874ofzu9dc.fsf@kobe.laptop> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: freebsd-chat@freebsd.org Subject: Re: is strlen()'s read-4-bytes-ahead a standard? X-BeenThere: freebsd-chat@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Non technical items related to the community List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 16 Jul 2010 08:30:50 -0000 On Fri, 16 Jul 2010 09:41:23 +0200, "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 | 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.