From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1LbF0d-0004tV-EK for mharc-grub-devel@gnu.org; Sun, 22 Feb 2009 09:08:43 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LbF0a-0004tM-Tj for grub-devel@gnu.org; Sun, 22 Feb 2009 09:08:40 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LbF0Y-0004tA-Dx for grub-devel@gnu.org; Sun, 22 Feb 2009 09:08:39 -0500 Received: from [199.232.76.173] (port=48371 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LbF0Y-0004t7-8h for grub-devel@gnu.org; Sun, 22 Feb 2009 09:08:38 -0500 Received: from mail-bw0-f160.google.com ([209.85.218.160]:44731) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LbF0X-0004Mf-Et for grub-devel@gnu.org; Sun, 22 Feb 2009 09:08:38 -0500 Received: by bwz4 with SMTP id 4so4048148bwz.18 for ; Sun, 22 Feb 2009 06:08:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:subject:from:to:in-reply-to :references:content-type:date:message-id:mime-version:x-mailer; bh=fmMjrhpgTYBPzuryN440RqmXCHUBcfTmZ16qzbhi5IA=; b=aJJVWq0T42vbscsbEVsaf+iOjr3A4B2dVE2FKfZNlpb99XiD+g7nhfvf77MH7Fbzf4 t/FVE92jtvbAeUMs3A8tZ0szqexkuOxKsWcMOe6F6y60yvO3k/1v2g7mdShmeX0vmYDS jdZAuwKQIEX03WpmySgwHiZMB22oJy7m/3w2M= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=subject:from:to:in-reply-to:references:content-type:date:message-id :mime-version:x-mailer; b=nNSTx+NMFdzmZLWoqufOKLBwXp7kqx/xiHBd0ocT/x9Jqy+++yxlD7pCX8VeIQaZl9 tOYHPssRAVva38zU8cMieYvgio2ipGgQf8j/Wpl2+5LF7RBP2al9l1fZJD0FvB8SC+MS uUomaJXOjDsHl3snP0DYTBxepAOpVkmAIbzIA= Received: by 10.103.93.18 with SMTP id v18mr2809835mul.43.1235311715783; Sun, 22 Feb 2009 06:08:35 -0800 (PST) Received: from ?192.168.1.100? (213.37.137.93.dyn.user.ono.com [213.37.137.93]) by mx.google.com with ESMTPS id n7sm1028467mue.36.2009.02.22.06.08.34 (version=SSLv3 cipher=RC4-MD5); Sun, 22 Feb 2009 06:08:35 -0800 (PST) From: Javier =?ISO-8859-1?Q?Mart=EDn?= To: The development of GRUB 2 In-Reply-To: <20090221131355.GF16068@thorin> References: <1234225160.10940.25.camel@localhost> <1234259444.3416.8.camel@fz.local> <1234266254.7325.12.camel@localhost> <20090221131355.GF16068@thorin> Content-Type: multipart/signed; micalg="pgp-sha1"; protocol="application/pgp-signature"; boundary="=-gYiizjNa6OeclImnYy+f" Date: Sun, 22 Feb 2009 15:08:39 +0100 Message-Id: <1235311719.21397.14.camel@localhost> Mime-Version: 1.0 X-Mailer: Evolution 2.24.3 X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) Subject: Re: [PATCH] r1986 broke FAT detection X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 22 Feb 2009 14:08:41 -0000 --=-gYiizjNa6OeclImnYy+f Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable El s=C3=A1b, 21-02-2009 a las 14:13 +0100, Robert Millan escribi=C3=B3: > On Tue, Feb 10, 2009 at 12:44:14PM +0100, Javier Mart=C3=ADn wrote: > > >=20 > > You're welcome. I see that nevertheless the "0 !=3D " comparisons were > > substituted for standard C int-to-bool-conversion-based comparisons. > > Maybe people should know the signature _and_ semantic contract of > > strncmp, but frequently they don't (I had to look it up in the > > handbook), and while the code that was committed may look like an > > "obvious error" to a wanderer (because, of course, comparison functions > > should return a semantic-bool, shouldn't they?), the version with the > > explicit "0 !=3D " checks at least looks like it was written like that = _on > > purpose_ (and the actual binary cost should be zero with any sensible > > compiler), thus making future developers on bug-fixing quests at least > > scratch their heads before proposing the change to the "if (!strncmp)" > > error. So, keeping the coding style consistent is important, but I thin= k > > a balance with readability is in order. Thus, you are the maintainers > > and you know what you're doing, but I think it's not worth to keep the > > coding style so strict as to become confusing. >=20 > I think you're confusing things. C has no boolean type. I know strcmp > gives more info than just a semantic boolean, but in this case it's not > interesting to us. >=20 My point is that the current code _looks_ confusing: due to the lack of a proper boolean type in C (and no, C99 _Bool does not count either), functions that return "semantic-booleans" return int's instead, with the C convention of 0->false, other->true. This is a common convention, and there are heaps of functions that work like that. So many, in fact, that those invocations of strncmp are likely to look odd to someone that does not have the semantic contract (and not just the formal C signature) in mind; because under the "usual" convention the code _seems_ to be checking whether the filesystem is fat12, fat16 _and_ fat32 at once. However, the return value of strncmp is actually a semantic integer, and thus the Right Thing (TM, and sorry if I sound preaching) is to perform the very exact comparison we want, that is "strncmp() =3D=3D 0". As I already said, the explicit integer comparison would, given its relative rarity in normal C code, at least make people scratch their heads before thinking "hey, this comparison should use 'or's instead of 'and's": in fact, I think that's the advantage of my version - it keeps the original "x or y or z" logical structure of the comparison. Given that the cost in binary size would most likely be zero for any average compiler, I think the change is worth performing. --=20 -- Lazy, Oblivious, Rational Disaster -- Habbit --=-gYiizjNa6OeclImnYy+f Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Esta parte del mensaje =?ISO-8859-1?Q?est=E1?= firmada digitalmente -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iQIcBAABAgAGBQJJoVxiAAoJEKSl+Fbdeo72oekP/iSLZ6rcp07XsijbyFmrHfb3 aD6tbJWKiMtUtr33Qj+ppEFvKMerlyjbqW+AkPtfeKmAoVgHXvOcm8gH3BxYEpbE li7Ou8GhCZRbyJo09FMtcFuYtBLbGPw4wvVnOOvt5y+kd3v49OVr4ciy6Albpt7W OXKq9Z2Jg1eR29/FCAjaXNAPosdSJBoiC2XaMOZq66puW/CZ2q3jMOq212Gk6YsI Npd+hSVQWS620YNftVFR6AMC4928UVN5ngGpICTszKrgo8II4bSV0IFrsK42d1cs jIyCtQgfzbAV/jItoBayvXL+Ea9jIHKq0grIN5argZCb/sPPSVimGMgT6IqPc6/W mLrvHnw/EZzebL7xdWqEkWQ7zpDFI0PrfkISuoutznTQ5em3I68nqwZ1y6fhbs2x BUZcLnJ/RwNSrhcbLiQpaCc+flXifs4r7NqimY2hq53LXRvu9rr/Jq4lMoVyDzN1 I0RuT5pCVXmrFDHuluhoIcemDp4iCU94HG6rtS3GzJXgXqEdVYroDMMaQJEvcuZp HAVYFCn3KprkPOpjIagMWKFohh7oYmAtXdFwdadqVvRAc0uA5BLjmnEUFNnLkDOr FuYiQbKCz4aCO1ZxkGoTMLI2LTO9QUpwR/vW08CaIPEh38MHSW865VuLLbhgiaFT Dnrx4SQCrg32Penk7bb8 =OYR5 -----END PGP SIGNATURE----- --=-gYiizjNa6OeclImnYy+f--