From: Michael Ellerman <michael@ellerman.id.au>
To: Geert Uytterhoeven <Geert.Uytterhoeven@sonycom.com>
Cc: Linux/PPC Development <linuxppc-dev@ozlabs.org>,
linux-sparse@vger.kernel.org, Al Viro <viro@ftp.linux.org.uk>
Subject: Re: cast truncates bits from constant value (8000000000000000 becomes 0)
Date: Sat, 02 Dec 2006 18:50:26 +1100 [thread overview]
Message-ID: <1165045826.6246.5.camel@concordia.ozlabs.ibm.com> (raw)
In-Reply-To: <Pine.LNX.4.62.0612011553100.30940@pademelon.sonytel.be>
[-- Attachment #1: Type: text/plain, Size: 2116 bytes --]
On Fri, 2006-12-01 at 15:55 +0100, Geert Uytterhoeven wrote:
> On Fri, 1 Dec 2006, Al Viro wrote:
> > On Fri, Dec 01, 2006 at 03:25:08PM +0100, Geert Uytterhoeven wrote:
> > > On Tue, 21 Nov 2006, Geoff Levand wrote:
> > > > +enum ps3_vendor_id {
> > > > + PS3_VENDOR_ID_NONE = 0,
> > > > + PS3_VENDOR_ID_SONY = 0x8000000000000000UL,
> > > > +};
> > >
> > > I've just ran `make C=1' (PPC in 64-bit mode, and sparse is called with -m64),
> > > and noticed that sparse (cloned from
> > > git://git.kernel.org/pub/scm/devel/sparse/sparse.git a few minutes ago)
> > > complains about the second value with:
> > >
> > > | warning: cast truncates bits from constant value (8000000000000000 becomes 0)
> > >
> > > Section 6.7.2.2.4 of C99 says:
> > >
> > > | Each enumerated type shall be compatible with char, a signed integer type, or
> > > | an unsigned integer type. The choice of type is implementation-defined, but
> > > | shall be capable of representing the values of all the members of the
> > > | enumeration.
> >
> > FWIW, that code is *not* valid C99; note that all enumeration members must
> > fit the range of int (see 6.7.2.2.2). What you quote speaks about the
>
> You're right. I missed that one.
>
> > IOW, you are using a gccism in an area where gcc is bloody inconsistent
> > in the set of bugs it shows in different versions.
>
> Hmmm...
>
> > Generally safe way is to split the anonymous huge enum members into
> > single-element enums and pray that gcc will at least stay consistent
> > in handling of those.
>
> Or fall back to #defines, which is what we were trying to avoid in the first
> place (i.e. group related values together in enums)...
The enum achieves very little in this case IMHO, it's just a more
verbose way of #defining - and it doesn't even have reliable semantics.
cheers
--
Michael Ellerman
OzLabs, IBM Australia Development Lab
wwweb: http://michael.ellerman.id.au
phone: +61 2 6212 1183 (tie line 70 21183)
We do not inherit the earth from our ancestors,
we borrow it from our children. - S.M.A.R.T Person
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
next prev parent reply other threads:[~2006-12-02 7:50 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-11-22 4:20 [PATCH 8/14] powerpc: add ps3 platform repository support Geoff Levand
2006-12-01 14:25 ` cast truncates bits from constant value (8000000000000000 becomes 0) Geert Uytterhoeven
2006-12-01 14:39 ` Al Viro
2006-12-01 14:55 ` Geert Uytterhoeven
2006-12-02 7:50 ` Michael Ellerman [this message]
2006-12-01 15:30 ` Linus Torvalds
2006-12-01 16:51 ` Geoff Levand
2006-12-01 20:20 ` Linus Torvalds
2006-12-01 20:49 ` Derek M Jones
2006-12-01 21:00 ` Al Viro
2006-12-01 21:19 ` Linus Torvalds
2006-12-01 20:50 ` Linus Torvalds
2006-12-01 21:17 ` Geoff Levand
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=1165045826.6246.5.camel@concordia.ozlabs.ibm.com \
--to=michael@ellerman.id.au \
--cc=Geert.Uytterhoeven@sonycom.com \
--cc=linux-sparse@vger.kernel.org \
--cc=linuxppc-dev@ozlabs.org \
--cc=viro@ftp.linux.org.uk \
/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).