linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: David Miller <davem@davemloft.net>
Cc: akpm@linux-foundation.org, sparclinux@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [GIT] Sparc
Date: Tue, 17 Aug 2010 18:31:50 -0700	[thread overview]
Message-ID: <AANLkTikQ1dGw0aO10_ZwmVEc-JAVhB==3HS7SrWycE49@mail.gmail.com> (raw)
In-Reply-To: <20100817.180325.104051399.davem@davemloft.net>

On Tue, Aug 17, 2010 at 6:03 PM, David Miller <davem@davemloft.net> wrote:
>
> Among other things, this fixes the rwsem signedness issue we
> were discussing earlier today.

Your commit message is missing the C rules for hex constants. It says

  "hex constants are unsigned unless explicitly casted or negated."

and that's not true.

The rule is that hex constants are signed _except_ if they don't fit
in a signed.

So with a 32-bit 'int', 0x123 is signed, but 0x80000000 is unsigned.

So the reason (-0x00010000) is signed is _not_ because of the
negation, but simply because 0x00010000 fits in a signed int. So for
example, the constant (-0xf0000000) is still unsigned, despite the
negation.

So to make something signed, you need to either cast it, make sure it
fits in a signed int, use the 'l' postfix (which also makes it long,
of course), or use a decimal representation. So

   #define X 4294901760

is a _signed_ constant with same value as 0xffff0000 (but it's "signed
long", because the rules for decimal numbers and hex numbers are
different: a decimal number is always signed and because it doesn't
fit in 'int' it will extend to 'long'. A hex number is first done as
unsigned, and only extended to long if it doesn't fit in that.

To make things _really_ confused, sometimes the types actually depend
on whether you're compiling with the c90 standards. A decimal constant
is _always_ signed in traditional C - it goes from 'int' to 'long',
and stays 'long' even if it doesn't fit (ie with a 32-bit long,
2147483648 is of type 'long' even though it doesn't fit in 'long' and
is negative). But in c90, it does from 'int' to 'long' to 'unsigned
long'.

Or maybe it was the other way around. I forget.

Confused yet?

The basic rule becomes: never _ever_ overflow 'int' in a constant,
without specifying the exact type you want. That way you avoid all the
subtle cases.

                     Linus

  reply	other threads:[~2010-08-18  1:32 UTC|newest]

Thread overview: 380+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-18  1:03 [GIT] Sparc David Miller
2010-08-18  1:31 ` Linus Torvalds [this message]
2010-08-18  1:59   ` Linus Torvalds
2010-08-18  2:14     ` David Miller
2010-08-18  4:38       ` 64-bit ppc rwsem (was: Re: [GIT] Sparc) Benjamin Herrenschmidt
2010-08-18  5:03         ` Benjamin Herrenschmidt
2010-08-18  5:28           ` 64-bit ppc rwsem David Miller
2010-08-18  5:39             ` Sam Ravnborg
2010-08-18  5:48               ` David Miller
2010-08-19  5:23             ` Benjamin Herrenschmidt
2010-08-19  5:29               ` David Miller
2010-08-19 10:24                 ` Benjamin Herrenschmidt
2010-08-20  5:14                 ` [PATCH 1/2] powerpc: Make rwsem use "long" type Benjamin Herrenschmidt
2010-08-24  1:37                   ` Timur Tabi
2010-08-20  5:14                 ` [PATCH 2/2] rwsem: Move powerpc atomic-long based implementation to asm-generic Benjamin Herrenschmidt
2010-08-20  6:43                   ` Sam Ravnborg
2010-08-24  1:32                     ` Benjamin Herrenschmidt
2010-08-23  4:39                   ` David Miller
2010-08-23 13:44                 ` 64-bit ppc rwsem Arnd Bergmann
2010-08-23 22:01                   ` Benjamin Herrenschmidt
2010-08-23 22:18                     ` David Miller
2010-08-24  1:31                       ` Benjamin Herrenschmidt
2010-08-24 12:06                         ` Arnd Bergmann
2010-08-18  2:12   ` [GIT] Sparc David Miller
2010-08-18  2:50     ` Al Viro
  -- strict thread matches above, loose matches on Subject: below --
2021-03-08 23:46 [GIT] SPARC David Miller
2021-03-09  0:19 ` John Paul Adrian Glaubitz
2021-03-09 19:08   ` David Miller
2021-03-09 19:27     ` Linus Torvalds
2021-03-10  0:24       ` David Miller
2021-03-10  1:15         ` David Miller
2021-03-10  1:17           ` Linus Torvalds
2021-03-10  1:18             ` David Miller
2021-03-10 10:40         ` Geert Uytterhoeven
2021-03-10 13:14           ` Konstantin Ryabitsev
2021-02-23 21:21 [GIT] Sparc David Miller
2021-02-23 23:36 ` pr-tracker-bot
2020-06-08  0:16 David Miller
2020-06-08  0:35 ` pr-tracker-bot
2020-04-06 18:25 David Miller
2020-04-07 19:55 ` pr-tracker-bot
2020-02-02 10:57 David Miller
2020-02-02 20:20 ` pr-tracker-bot
2020-01-30 10:19 David Miller
2020-01-30 18:00 ` pr-tracker-bot
2019-07-13  6:17 David Miller
2019-07-13 23:15 ` pr-tracker-bot
2019-06-03  5:21 David Miller
2019-06-03 17:35 ` pr-tracker-bot
2019-05-09 21:35 David Miller
2019-05-09 22:15 ` pr-tracker-bot
2018-12-22 23:46 David Miller
2018-12-26 19:20 ` pr-tracker-bot
2018-12-21 20:42 David Miller
2018-12-21 22:30 ` pr-tracker-bot
2018-12-03  5:33 David Miller
2018-12-03 17:55 ` pr-tracker-bot
2018-11-01  1:44 David Miller
2018-11-01 16:15 ` Linus Torvalds
2018-10-26 23:08 David Miller
2018-10-27  0:17 ` Linus Torvalds
2018-10-25 18:28 David Miller
2018-10-26  1:30 ` Linus Torvalds
2018-10-24  3:31 David Miller
2018-10-24  5:43 ` Linus Torvalds
2018-10-18 23:33 David Miller
2018-10-19  7:16 ` Greg KH
2018-10-16  2:39 David Miller
2018-10-16 16:55 ` Greg KH
2018-10-08  6:48 David Miller
2018-10-08 14:26 ` Greg KH
2018-08-22  5:16 David Miller
2018-06-09 14:21 David Miller
2018-04-30 20:12 David Miller
2018-04-03 15:31 David Miller
2018-03-15 21:20 David Miller
2018-02-01 15:20 David Miller
2018-01-24 23:23 David Miller
2017-12-31  4:17 David Miller
2017-11-29 20:17 David Miller
2017-11-18  3:15 David Miller
2017-09-10  3:24 David Miller
2017-08-21 21:01 David Miller
2017-08-10  5:26 David Miller
2017-08-04 17:11 David Miller
2017-07-17 20:57 David Miller
2017-07-12  4:05 David Miller
2017-07-08 10:40 David Miller
2017-06-06 20:57 David Miller
2017-05-18 18:03 David Miller
2017-05-09 20:04 David Miller
2017-04-26 19:22 David Miller
2017-04-18 20:20 David Miller
2017-04-07 21:21 David Miller
2017-02-24 16:34 David Miller
2017-01-30 22:37 David Miller
2016-12-12 15:10 David Miller
2016-12-06 17:19 David Miller
2016-11-28 21:03 David Miller
2016-11-21 18:41 David Miller
2016-10-31  1:04 David Miller
2016-10-06  7:57 David Miller
2016-10-02 13:02 David Miller
2016-07-29 18:15 David Miller
2016-06-29 13:06 David Miller
2016-06-29 13:32 ` David Miller
2016-06-01  4:17 David Miller
2016-05-22  6:03 David Miller
2016-05-02  5:10 David Miller
2016-03-28 19:45 David Miller
2016-03-01  5:47 David Miller
2016-01-15 21:04 David Miller
2015-12-31 20:30 David Miller
2015-12-24 17:16 David Miller
2015-11-05 21:39 David Miller
2015-11-06  0:43 ` Linus Torvalds
2015-11-06  0:56   ` Linus Torvalds
2015-11-06  1:05     ` Julian Calaby
2015-11-06  6:44       ` Julia Lawall
2015-11-07  3:31         ` Julian Calaby
2015-11-07  6:04           ` Julia Lawall
2015-11-06  5:14   ` David Miller
2015-08-07  2:19 David Miller
2015-06-25 13:27 David Miller
2015-06-02  0:17 David Miller
2015-04-22  2:58 David Miller
2015-04-18 21:58 David Miller
2015-04-17 20:14 David Miller
2015-03-23 16:55 David Miller
2015-03-23 17:05 ` Linus Torvalds
2015-03-23 17:12   ` Linus Torvalds
2015-03-23 19:14     ` David Miller
2015-03-23 19:10   ` David Miller
2015-03-19  4:59 David Miller
2014-12-18 21:39 David Miller
2014-12-12 20:58 David Miller
2014-11-26 21:42 David Miller
2014-11-16 21:43 David Miller
2014-10-31 20:44 David Miller
2014-10-24 17:32 David Miller
2014-10-24 19:47 ` Linus Torvalds
2014-10-27 21:09   ` Andrew Morton
2014-10-27 22:43     ` David Miller
2014-10-28 10:49       ` Steve Capper
2014-10-19 17:26 David Miller
2014-10-15 18:45 David Miller
2014-10-10 20:01 David Miller
2014-08-14 23:17 David Miller
2014-08-12  4:01 David Miller
2014-08-06  5:03 David Miller
2014-07-22  5:38 David Miller
2014-06-16  6:45 David Miller
2014-05-22 21:53 David Miller
2014-05-06 15:30 David Miller
2014-05-06 16:29 ` Dave Jones
2014-05-06 17:13   ` David Miller
2014-03-24 19:18 David Miller
2014-02-21 17:42 David Miller
2014-01-29  8:51 David Miller
2014-01-05  2:04 David Miller
2013-11-19 22:18 David Miller
2013-11-14 23:19 David Miller
2013-10-03  3:52 David Miller
2013-10-01 17:57 David Miller
2013-09-05 20:44 David Miller
2013-09-05 22:32 ` Sergei Shtylyov
2013-09-06  2:54   ` David Miller
2013-07-10 21:00 David Miller
2013-06-19  9:28 David Miller
2013-05-05  2:42 David Miller
2013-04-25  0:08 David Miller
2013-04-21  1:16 David Miller
2013-03-19 21:18 David Miller
2013-02-20 22:09 David Miller
2013-02-14 20:14 David Miller
2012-12-20  0:15 David Miller
2012-12-13 20:11 David Miller
2012-12-03 20:33 David Miller
2012-11-23 19:48 David Miller
2012-11-10 19:21 David Miller
2012-10-17  5:05 David Miller
2012-10-12 19:26 David Miller
2012-10-10  1:26 David Miller
2012-10-08 20:18 David Miller
2012-10-10  5:11 ` Al Viro
2012-10-11  0:34   ` David Miller
2012-10-03  6:14 David Miller
2012-10-02 18:13 David Miller
2012-09-21 19:48 David Miller
2012-08-15  7:44 David Miller
2012-08-15  7:51 ` [GIT] Sparc David Miller
2012-07-26 23:58 David Miller
2012-06-15 22:41 David Miller
2012-05-30 22:38 David Miller
2012-05-24 21:32 David Miller
2012-05-21  9:03 David Miller
2012-05-21 17:37 ` Linus Torvalds
2012-05-21 18:24   ` Sam Ravnborg
2012-05-21 18:28     ` Linus Torvalds
2012-05-21 18:33       ` Linus Torvalds
2012-05-21 18:38       ` Sam Ravnborg
2012-05-10 20:52 David Miller
2012-04-21 20:58 David Miller
2012-04-13 19:24 David Miller
2012-04-13 19:46 ` Linus Torvalds
2012-04-13 20:12   ` David Miller
2012-04-13 21:50   ` Sam Ravnborg
2012-04-14  9:13     ` Ingo Molnar
2012-04-14 10:23       ` Sam Ravnborg
2012-04-14 10:50         ` Ingo Molnar
2012-04-04  8:03 David Miller
2012-03-31  1:37 David Miller
2012-03-30  7:39 David Miller
2012-03-30 10:02 ` Sam Ravnborg
2012-01-26 21:55 David Miller
2012-01-09 22:22 David Miller
2011-12-23 22:11 David Miller
2011-12-16 20:22 David Miller
2011-11-18 19:22 David Miller
2011-11-08 20:07 David Miller
2011-10-31  8:32 David Miller
2011-10-20  9:48 David Miller
2011-09-29 19:31 David Miller
2011-08-30 18:13 David Miller
2011-08-29 16:50 David Miller
2011-08-24  6:34 David Miller
2011-08-19  4:54 David Miller
2011-08-15 22:47 David Miller
2011-08-12  1:08 David Miller
2011-08-07 22:48 David Miller
2011-08-05 11:25 David Miller
2011-07-28  8:46 David Miller
2011-07-28 10:08 ` Anca Emanuel
2011-07-16 17:48 David Miller
2011-06-09 23:14 David Miller
2011-05-23  4:52 David Miller
2011-05-12  4:42 David Miller
2011-04-01  6:33 David Miller
2011-03-25 21:05 David Miller
2011-03-21  2:51 David Miller
2011-03-17  3:06 David Miller
2011-02-17 21:34 David Miller
2011-01-12  0:26 David Miller
2011-01-06 22:48 David Miller
2010-12-14 20:11 David Miller
2010-10-29  3:46 David Miller
2010-09-22 18:10 David Miller
2010-09-22 18:32 ` Al Viro
2010-09-22 18:46   ` Linus Torvalds
2010-09-22 18:53     ` Al Viro
2010-09-22 19:04       ` Al Viro
2010-09-22 19:08       ` Linus Torvalds
2010-09-22 19:53         ` Al Viro
2010-09-22 20:43           ` Al Viro
2010-09-22 21:15             ` David Miller
2010-09-22 23:12               ` Al Viro
2010-09-24  4:48                 ` David Miller
2010-09-23  0:27               ` Al Viro
2010-09-24  4:53                 ` David Miller
2010-09-23  4:59         ` Al Viro
2010-09-24  5:01           ` David Miller
2010-09-11  4:25 David Miller
2010-08-24  9:02 David Miller
2010-08-09 10:28 David Miller
2010-08-05  0:21 David Miller
2010-07-21  4:25 [GIT] SPARC David Miller
2010-05-19 19:50 [GIT] Sparc David Miller
2010-04-20  8:49 [GIT]: Sparc David Miller
2010-04-13 11:43 [GIT] Sparc David Miller
2010-04-04  8:15 David Miller
2010-03-29 20:11 David Miller
2010-03-16 21:46 [GIT]: Sparc David Miller
2010-03-14  2:17 David Miller
2010-03-14 14:34 ` Geert Uytterhoeven
2010-03-14 21:24   ` David Miller
2010-03-04  8:28 David Miller
2010-03-02 12:41 David Miller
2010-02-22  2:32 David Miller
2010-02-19  7:29 David Miller
2010-02-20  0:23 ` David Miller
2010-02-10 18:04 David Miller
2010-02-11 20:45 ` David Miller
2010-01-26  0:56 David Miller
2010-01-26  9:23 ` Alexander Beregalov
2010-01-26 12:12   ` David Miller
2010-01-05  7:28 David Miller
2009-12-15  6:04 David Miller
2009-12-06  3:35 David Miller
2009-11-30  9:14 David Miller
2009-11-09  5:31 David Miller
2009-10-14 21:14 David Miller
2009-10-05  9:02 David Miller
2009-09-25 21:31 David Miller
2009-09-17 17:54 David Miller
2009-09-16  8:43 David Miller
2009-09-12  4:01 David Miller
2009-09-04 12:27 David Miller
2009-08-26  3:38 David Miller
2009-06-19  7:08 David Miller
2009-06-16 12:23 David Miller
2009-06-01 10:26 David Miller
2009-04-22 10:48 David Miller
2009-04-16 11:12 David Miller
2009-04-08 23:08 David Miller
2009-03-30  0:11 David Miller
2009-03-28  1:18 David Miller
2009-03-26  9:08 David Miller
2009-03-23  8:40 David Miller
2009-03-12 15:58 David Miller
2009-02-25  7:15 David Miller
2009-02-10  4:21 David Miller
2009-02-04  7:27 David Miller
2009-01-26 22:57 David Miller
2009-01-16  0:02 David Miller
2009-01-11  7:56 David Miller
2009-01-08  1:19 David Miller
2009-01-06  2:34 David Miller
2008-12-29  4:51 David Miller
2008-12-18  3:57 David Miller
2008-12-04 19:58 David Miller
2008-12-02  7:19 David Miller
2008-11-17  7:51 David Miller
2008-11-11  6:23 David Miller
2008-11-02  7:45 David Miller
2008-10-31  6:02 David Miller
2008-10-24  0:33 David Miller
2008-10-13  7:00 David Miller
2008-10-11 22:33 David Miller
2008-09-22 23:18 David Miller
2008-09-19  2:28 David Miller
2008-09-12 22:59 David Miller
2008-09-09 23:13 David Miller
2008-09-08 20:59 David Miller
2008-08-30 20:01 David Miller
2008-08-25  3:40 David Miller
2008-08-18  5:39 David Miller
2008-08-13 23:45 David Miller
2008-08-14  0:21 ` David Miller
2008-08-08  6:20 David Miller
2008-08-02  5:12 David Miller
2008-07-28  1:09 David Miller
2008-07-25 22:21 David Miller
2008-07-24  6:27 David Miller
2008-07-23  0:14 David Miller
2008-07-21  6:41 David Miller
2008-06-13  4:15 David Miller
2008-06-04 23:56 David Miller
2008-05-26  6:18 David Miller
2008-05-22  4:55 David Miller
2008-05-20 23:04 David Miller
2008-05-16 22:27 David Miller
2008-05-15  0:22 David Miller
2008-05-14  1:19 David Miller
2008-05-12  7:58 David Miller
2008-05-11  9:28 David Miller
2008-05-11 11:30 ` Christoph Hellwig
2008-05-09  0:05 David Miller
2008-05-07 23:39 David Miller
2008-05-08  0:06 ` Linus Torvalds
2008-05-08  1:16   ` David Miller
2008-05-07  1:14 David Miller
2008-05-03  3:02 David Miller
2008-04-30  8:33 David Miller
2008-04-28  0:01 David Miller
2008-04-28  6:29 ` Christoph Hellwig
2008-04-28  6:37   ` David Miller
2008-04-25 10:25 David Miller
2008-04-24 11:02 David Miller
2008-04-24 15:39 ` Linus Torvalds
2008-04-24 15:41   ` David Miller
2008-04-21 22:32 David Miller
2008-04-21 22:50 ` Roland Dreier
2008-04-21 23:54   ` David Miller
2008-04-21 23:10 ` Linus Torvalds
2008-04-21 23:18   ` Al Viro
2008-04-21 23:25     ` Al Viro
2008-04-22  0:16       ` David Miller
2008-04-22  0:26         ` Al Viro
2008-04-21 23:32     ` Linus Torvalds
2008-04-22  0:06   ` David Miller
2008-04-22  0:20     ` Linus Torvalds

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='AANLkTikQ1dGw0aO10_ZwmVEc-JAVhB==3HS7SrWycE49@mail.gmail.com' \
    --to=torvalds@linux-foundation.org \
    --cc=akpm@linux-foundation.org \
    --cc=davem@davemloft.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sparclinux@vger.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;
as well as URLs for NNTP newsgroup(s).