Commit cbacb5ab authored by Joe Perches's avatar Joe Perches Committed by Jonathan Corbet

docs: printk-formats: Stop encouraging use of unnecessary %h[xudi] and %hh[xudi]

Standard integer promotion is already done and %hx and %hhx is useless
so do not encourage the use of %hh[xudi] or %h[xudi].

As Linus said in:
https://lore.kernel.org/lkml/CAHk-=wgoxnmsj8GEVFJSvTwdnWm8wVJthefNk2n6+4TC=20e0Q@mail.gmail.com/

It's a pointless warning, making for more complex code, and
making people remember esoteric printf format details that have no
reason for existing.

The "h" and "hh" things should never be used. The only reason for them
being used if if you have an "int", but you want to print it out as a
"char" (and honestly, that is a really bad reason, you'd be better off
just using a proper cast to make the code more obvious).

So if what you have a "char" (or unsigned char) you should always just
print it out as an "int", knowing that the compiler already did the
proper type conversion.
Signed-off-by: default avatarJoe Perches <joe@perches.com>
Reviewed-by: default avatarLouis Taylor <louis@kragniz.eu>
Signed-off-by: default avatarJonathan Corbet <corbet@lwn.net>
parent 82f12ab3
...@@ -13,10 +13,10 @@ Integer types ...@@ -13,10 +13,10 @@ Integer types
If variable is of Type, use printk format specifier: If variable is of Type, use printk format specifier:
------------------------------------------------------------ ------------------------------------------------------------
char %hhd or %hhx char %d or %x
unsigned char %hhu or %hhx unsigned char %u or %x
short int %hd or %hx short int %d or %x
unsigned short int %hu or %hx unsigned short int %u or %x
int %d or %x int %d or %x
unsigned int %u or %x unsigned int %u or %x
long %ld or %lx long %ld or %lx
...@@ -25,10 +25,10 @@ Integer types ...@@ -25,10 +25,10 @@ Integer types
unsigned long long %llu or %llx unsigned long long %llu or %llx
size_t %zu or %zx size_t %zu or %zx
ssize_t %zd or %zx ssize_t %zd or %zx
s8 %hhd or %hhx s8 %d or %x
u8 %hhu or %hhx u8 %u or %x
s16 %hd or %hx s16 %d or %x
u16 %hu or %hx u16 %u or %x
s32 %d or %x s32 %d or %x
u32 %u or %x u32 %u or %x
s64 %lld or %llx s64 %lld or %llx
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment