linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Xi Wang <xi.wang@gmail.com>,
	linux-sparse@vger.kernel.org, Christopher Li <sparse@chrisli.org>,
	Pekka Enberg <penberg@kernel.org>
Subject: Re: [RFC][PATCH] fix casting constant to _Bool
Date: Sat, 16 Jun 2012 19:59:41 +0300	[thread overview]
Message-ID: <20120616165941.GG4400@mwanda> (raw)
In-Reply-To: <CA+55aFwTyqQ5WBL7b8fbCeBhM_sumQXc-SaKSzwOcwk431Vf9g@mail.gmail.com>

On Sat, Jun 16, 2012 at 09:32:50AM -0700, Linus Torvalds wrote:
> On Fri, Jun 15, 2012 at 11:55 PM, Xi Wang <xi.wang@gmail.com> wrote:
> > Casting to _Bool requires a zero test rather than truncation.
> 
> Ack. _Bool is very special (and rather non-C-like).
> 
> > BTW, this patch also disables the warning "cast truncates bits from
> > constant value".  Does that sound good?
> 
> For cast to _Bool, that is correct. Since it doesn't truncate the
> value, the upper bits are not ignored as they are with other casts.
> 

It's pretty rare to see a cast to bool that truncates the value.
My feeling is that most times they are bugs.  I just saw one of
these a couple weeks ago:

http://www.spinics.net/lists/linux-iio/msg05573.html

I wish the error message could be fixed so it says 1 instead of 0.

old: warning: cast truncates bits from constant value (2 becomes 0)
new: warning: cast truncates bits from constant value (2 becomes 1)

regards,
dan carpenter
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2012-06-16 17:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-16  6:55 [RFC][PATCH] fix casting constant to _Bool Xi Wang
2012-06-16  7:10 ` Pekka Enberg
2012-06-16 16:32 ` Linus Torvalds
2012-06-16 16:59   ` Dan Carpenter [this message]
2012-06-16 17:20     ` Linus Torvalds
2012-06-17 18:44       ` Xi Wang

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=20120616165941.GG4400@mwanda \
    --to=dan.carpenter@oracle.com \
    --cc=linux-sparse@vger.kernel.org \
    --cc=penberg@kernel.org \
    --cc=sparse@chrisli.org \
    --cc=torvalds@linux-foundation.org \
    --cc=xi.wang@gmail.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).