All of lore.kernel.org
 help / color / mirror / Atom feed
From: Al Viro <viro@ftp.linux.org.uk>
To: ricknu-0@student.ltu.se
Cc: linux-sparse@vger.kernel.org
Subject: Re: Booleans, what a wonderful type!
Date: Thu, 19 Jul 2007 08:30:52 +0100	[thread overview]
Message-ID: <20070719073052.GU21668@ftp.linux.org.uk> (raw)
In-Reply-To: <1184805503.469eb27f82f96@portal.student.luth.se>

On Thu, Jul 19, 2007 at 02:38:23AM +0200, ricknu-0@student.ltu.se wrote:
> > Er...  Of _course_ booleans are values.  And yes, you can say true + false.
> > Guaranteed to evaluate to int, value of expression being 1.  It's perfectly
> > correct C99.  Same as true + true is guaranteed to be 2 (int, again);
> > assigning
> > that to _Bool variable is guaranteed to give 1, aka true (see the rules
> > for conversion to _Bool).
> Can you really say it really is a value? With C definition: ex an positiv
> integer value => 'true' => value not zero, if converted from integer to boolean
> and back. A value would return a specific value on the secound step, right?

Yes.  RTFStandard, please.
 
> > Now, sparse handling of _Bool sucks in quite a few places (e.g. conversion
> > to it is not reduction modulo 2, it's comparison with 0), but I wonder if
> > that's what you have in mind...
> My main goal is to make it able to find possible places where an integer is used
> as an boolean.

I'm afraid that you are confused; what exactly do you mean by "boolean"?
Note that type of 1 == 1 is *not* _Bool; it's defined as int.  You can
convert it to _Bool, but that's it.

Please, read through the relevant sections of standard, starting with
6.3.1.2 and 6.3.1.1[2].  See also 6.5.3.4[5], 6.5.8, 6.5.9, 6.5.13 and
6.5.14 for operations resulting in int 0 or 1.  See 7.16 for stdbool
stuff.

      reply	other threads:[~2007-07-19  7:30 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-18  1:43 Booleans, what a wonderful type! ricknu-0
2007-07-18  2:19 ` Al Viro
2007-07-18  2:40   ` Brett Nash
2007-07-18 16:33   ` Josh Triplett
2007-07-19  0:23     ` ricknu-0
2007-07-18  2:25 ` Al Viro
2007-07-19  0:38   ` ricknu-0
2007-07-19  7:30     ` Al Viro [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=20070719073052.GU21668@ftp.linux.org.uk \
    --to=viro@ftp.linux.org.uk \
    --cc=linux-sparse@vger.kernel.org \
    --cc=ricknu-0@student.ltu.se \
    /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.