From: Randy Dunlap <randy.dunlap@oracle.com>
To: Alexey Dobriyan <adobriyan@gmail.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: How do I printk <type> correctly?
Date: Wed, 5 Nov 2008 10:23:35 -0800 [thread overview]
Message-ID: <20081105102335.b1fd995d.randy.dunlap@oracle.com> (raw)
In-Reply-To: <20081023114133.GA30187@x200.localdomain>
On Thu, 23 Oct 2008 15:41:33 +0400 Alexey Dobriyan wrote:
> If variable is of Type use printk format specifier.
> ---------------------------------------------------------
> int %d or %x
> unsigned int %u or %x
> long %ld ot %lx
> unsigned long %lu or %lx
> long long %lld or %llx
> unsigned long long %llu or %llx
> size_t %zu or %zx
> ssize_t %zd or %zx
Add, or is this one too infrequent to be listed here?
tcflag_t %lu or %lx or %lo
Since tcflag_t is unsigned int (on most $ARCH-es) or unsigned long (on sparc32),
use a cast to (unsigned long)flag when printing it.
[Yes, a sparc32 build gets lots of printk format warnings when printing tcflag_t
values.]
> Raw pointer value SHOULD be printed with %p.
>
> u64 SHOULD be printed with %llu/%llx, (unsigned long long):
>
> printk("%llu", (unsigned long long)u64_var);
>
> s64 SHOULD be printed with %lld/%llx, (long long):
>
> printk("%lld", (long long)s64_var);
>
> If type is dependent on config option (sector_t), use format specifier
> of biggest type and explicitly cast to it.
>
> Reminder: sizeof() result is of type size_t.
>
> Thank you for your cooperation.
> --
---
~Randy
prev parent reply other threads:[~2008-11-05 18:24 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-10-23 11:41 How do I printk <type> correctly? Alexey Dobriyan
2008-10-23 11:51 ` David John
2008-10-23 12:06 ` Alexey Dobriyan
2008-10-23 15:13 ` Johannes Berg
2008-10-23 20:40 ` David Miller
2008-10-24 8:41 ` Johannes Berg
2008-10-28 23:11 ` Randy Dunlap
2008-10-29 6:15 ` Artem Bityutskiy
2008-10-29 8:00 ` Artem Bityutskiy
2008-10-29 15:34 ` Randy Dunlap
2008-10-29 15:36 ` Artem Bityutskiy
2008-10-29 15:43 ` Randy Dunlap
2008-11-05 18:23 ` Randy Dunlap [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=20081105102335.b1fd995d.randy.dunlap@oracle.com \
--to=randy.dunlap@oracle.com \
--cc=adobriyan@gmail.com \
--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).