linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Dave Airlie <airlied@gmail.com>,
	Daniel Vetter <daniel.vetter@ffwll.ch>,
	dri-devel <dri-devel@lists.freedesktop.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Arnd Bergmann <arnd@arndb.de>
Subject: Re: [git pull] drm for 5.19-rc1
Date: Tue, 7 Jun 2022 11:15:06 -0700	[thread overview]
Message-ID: <CAHk-=wgcv_YewP0rgwR1+gj3YF-7Jz8WPVzDgndx0DVMVKzV=Q@mail.gmail.com> (raw)
In-Reply-To: <CAMuHMdXb5-gOVRsQx6tDqjQMD9cC-p=o56VuF2cBPWyMFRgHMA@mail.gmail.com>

On Tue, Jun 7, 2022 at 3:23 AM Geert Uytterhoeven <geert@linux-m68k.org> wrote:
>
> These header files are heavy users of large constants lacking the "U"
> suffix e.g.:
>
>     #define NB_ADAPTER_ID__SUBSYSTEM_ID_MASK 0xFFFF0000L

As Andreas says, this is not undefined behavior.

A hexadecimal integer constant will always get a type that fits the
actual value. So on a 32-bit architecture, because 0xFFFF0000 doesn't
fit in 'long', it will automatically become 'unsigned long'.

Now, a C compiler might still warn about such implicit type
conversions, but I'd be a bit surprised if any version of gcc actually
would do that, because this behavior for hex constants is *very*
traditional, and very common.

It's also true that the type of the constant - but not the value -
will be different on 32-bit and 64-bit architectures (ie on 64-bit, it
will be plain "long" and never extended to "unsigned long", because
the hex value obviously fits just fine).

I don't see any normal situation where that really matters, since any
normal use will have the same result.

The case you point to at

  https://lore.kernel.org/r/CAK8P3a0QrihBR_2FQ7uZ5w2JmLjv7czfrrarCMmJOhvNdJ3p9g@mail.gmail.com

is very different, because the constant "1" is always just a plain
signed "int". So when you do "(1 << 31)", that is now a signed integer
with the top bit set, and so it will have an actual negative value,
and that can cause various problems (when right-shifted, or when
compared to other values).

But hexadecimal constants can be signed types, but they never have
negative values.

                 Linus

  parent reply	other threads:[~2022-06-07 20:35 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-25  6:06 [git pull] drm for 5.19-rc1 Dave Airlie
2022-05-25 23:23 ` Linus Torvalds
2022-05-26  0:09 ` pr-tracker-bot
2022-06-07 10:22 ` Geert Uytterhoeven
2022-06-07 16:50   ` Andreas Schwab
2022-06-07 18:15   ` Linus Torvalds [this message]
2022-06-07 19:12     ` Geert Uytterhoeven

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='CAHk-=wgcv_YewP0rgwR1+gj3YF-7Jz8WPVzDgndx0DVMVKzV=Q@mail.gmail.com' \
    --to=torvalds@linux-foundation.org \
    --cc=airlied@gmail.com \
    --cc=arnd@arndb.de \
    --cc=daniel.vetter@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=geert@linux-m68k.org \
    --cc=linux-kernel@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).