From: Linus Torvalds <torvalds@linux-foundation.org>
To: "Frédéric Weisbecker" <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>,
Benjamin Herrenschmidt <benh@kernel.crashing.org>,
Kumar Gala <galak@kernel.crashing.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Jeremy Fitzhardinge <jeremy@goop.org>,
Becky Bruce <becky.bruce@freescale.com>
Subject: Re: [git pull] core kernel updates for v2.6.28
Date: Thu, 16 Oct 2008 15:57:04 -0700 (PDT) [thread overview]
Message-ID: <alpine.LFD.2.00.0810161548520.3288@nehalem.linux-foundation.org> (raw)
In-Reply-To: <c62985530810161543q23f9ae75jb08ff986a214da0@mail.gmail.com>
On Fri, 17 Oct 2008, Frédéric Weisbecker wrote:
>
> 2008/10/17 Linus Torvalds <torvalds@linux-foundation.org>:
> > The fact is, that second argument was a "ptrdiff_t", which is neither
> > "int" nor "long". It should be "%td" I think. But the thing is, when you
> > fix a warning, you should damn well know what the hell you're doing, not
> > just shut it up.
>
> Sorry, I made some falses assumptions about the printed type I guess...
Well, the thing is, on 32-bit x86, ptrdiff_t is "int". And on 64-bit, it's
"long". And on some (most?) other architectures, it's "long" regardless of
whether it's 32-bit or 64-bit.
So you fixed a warnign on x86-32, but you introduced it just about
everywhere else.
And it so happens that the old use of "%ld" was better than "%d", because
regardless of the exact type of ptrdiff_t, with gcc it is essentially
always going to be at least the same _size_ as "long". IOW, even when it's
"int", it will always print out correctly with "%ld", despite the format
warning. IOW, the type may be "wrong" from a C standards standpoint, but
it will work in practice.
In contrast, using "%d" can actually print it out wrong, because it will
be literally the wrong physical size, not just a type issue on a C level.
So depending on calling conventions, you might end up with the upper bits
cleared, or even the wrong bits printed out.
Using "%td" is always right, assuming the underlying printing library is
recent enough to know about it. And the kernel has known about %td for the
last three years.
Linus
next prev parent reply other threads:[~2008-10-16 22:57 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-10-15 12:50 Ingo Molnar
2008-10-16 22:32 ` Linus Torvalds
2008-10-16 22:43 ` Frédéric Weisbecker
2008-10-16 22:57 ` Linus Torvalds [this message]
2008-10-16 23:16 ` Frédéric Weisbecker
2008-10-16 23:05 ` Benjamin Herrenschmidt
2008-10-17 0:40 ` Benjamin Herrenschmidt
2008-10-17 0:41 ` Benjamin Herrenschmidt
2008-10-17 6:23 ` [git pull] core kernel fixes Ingo Molnar
2008-10-18 2:58 ` [git pull] core kernel updates for v2.6.28 Becky Bruce
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=alpine.LFD.2.00.0810161548520.3288@nehalem.linux-foundation.org \
--to=torvalds@linux-foundation.org \
--cc=akpm@linux-foundation.org \
--cc=becky.bruce@freescale.com \
--cc=benh@kernel.crashing.org \
--cc=fweisbec@gmail.com \
--cc=galak@kernel.crashing.org \
--cc=jeremy@goop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
/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
Powered by JetHome