public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Fengguang Wu <fengguang.wu@intel.com>
To: Tejun Heo <tj@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	kbuild-all@01.org, Christopher Li <sparse@chrisli.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: kernel/workqueue.c:4435:61: sparse: expression using sizeof bool
Date: Sat, 8 Jun 2013 10:15:09 +0800	[thread overview]
Message-ID: <20130608021509.GA13207@localhost> (raw)
In-Reply-To: <20130608020549.GN14781@mtj.dyndns.org>

// CC sparse people.

On Fri, Jun 07, 2013 at 07:05:49PM -0700, Tejun Heo wrote:
> Hello, Andrew.
> 
> On Fri, Jun 07, 2013 at 06:46:14PM -0700, Andrew Morton wrote:
> > I believe sizeof(bool) can vary between compilers (on gcc it's 1) but
> > that doesn't matter here.
> 
> Looking at the warning, I originally suspected that maybe the standard
> was crazy enough to allow mixed usages of different sizes for bool as
> the compiler sees fit.  Just scanned the spec, nothing that insane.
> It's a proper integeral type, so I'm now more puzzled why sparse is
> warning about sizeof(bool).
> 
> > sizeof(enum) can vary between compilers as well.  In fact I've seen a
> > compiler which used 2 if the enumerated values were 0..65535, and 4
> > otherwise.  So warning about sizeof(enum) would be a bit more useful
> > than about sizeof(bool).
> 
> Oh yeah, gcc does that too.  If the enum definition contains a number
> larger than 32bit, it'll grow it to 64bit.
> 
>  #include <stdio.h>
> 
>  enum { ENUM_A = 1LU };
>  enum { ENUM_B = 1LU << 31 };
>  enum { ENUM_C = 1LU << 32 };
> 
>  int main(void)
>  {
> 	 printf("%zu %zu %zu\n", sizeof(ENUM_A), sizeof(ENUM_B), sizeof(ENUM_C));
> 	 return 0;
>  }
> 
>  $ ./a.out
>  4 4 8
> 
> Whether sparse should trigger a warning on it, I don't know.
> 
> Thanks.
> 
> -- 
> tejun

      parent reply	other threads:[~2013-06-08  2:15 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <51afd3ac.1kKgJcnM4PAV+Agb%fengguang.wu@intel.com>
     [not found] ` <20130607141521.4000962d5ac0d7fcd54800cf@linux-foundation.org>
     [not found]   ` <20130607220351.GE14781@mtj.dyndns.org>
2013-06-07 23:50     ` kernel/workqueue.c:4435:61: sparse: expression using sizeof bool Fengguang Wu
     [not found]     ` <20130607184614.45418364.akpm@linux-foundation.org>
     [not found]       ` <20130608020549.GN14781@mtj.dyndns.org>
2013-06-08  2:15         ` Fengguang Wu [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=20130608021509.GA13207@localhost \
    --to=fengguang.wu@intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=kbuild-all@01.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sparse@chrisli.org \
    --cc=tj@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox