All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Javier Martín" <lordhabbit@gmail.com>
To: The development of GRUB 2 <grub-devel@gnu.org>
Subject: Re: [PATCH] r1986 broke FAT detection
Date: Sun, 22 Feb 2009 15:08:39 +0100	[thread overview]
Message-ID: <1235311719.21397.14.camel@localhost> (raw)
In-Reply-To: <20090221131355.GF16068@thorin>

[-- Attachment #1: Type: text/plain, Size: 2811 bytes --]

El sáb, 21-02-2009 a las 14:13 +0100, Robert Millan escribió:
> On Tue, Feb 10, 2009 at 12:44:14PM +0100, Javier Martín wrote:
> > > 
> > You're welcome. I see that nevertheless the "0 != " 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 != " 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 think
> > 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.
> 
> 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.
> 
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() == 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.

-- 
-- Lazy, Oblivious, Rational Disaster -- Habbit

[-- Attachment #2: Esta parte del mensaje está firmada digitalmente --]
[-- Type: application/pgp-signature, Size: 835 bytes --]

      reply	other threads:[~2009-02-22 14:08 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-10  0:19 [PATCH] r1986 broke FAT detection Javier Martín
2009-02-10  9:50 ` Felix Zielcke
2009-02-10 11:44   ` Javier Martín
2009-02-21 13:13     ` Robert Millan
2009-02-22 14:08       ` Javier Martín [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1235311719.21397.14.camel@localhost \
    --to=lordhabbit@gmail.com \
    --cc=grub-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.