Skip to content

Commit cbacb5a

Browse files
JoePerchesJonathan Corbet
authored andcommitted
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: Joe Perches <[email protected]> Reviewed-by: Louis Taylor <[email protected]> Signed-off-by: Jonathan Corbet <[email protected]>
1 parent 82f12ab commit cbacb5a

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

Documentation/core-api/printk-formats.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ Integer types
1313

1414
If variable is of Type, use printk format specifier:
1515
------------------------------------------------------------
16-
char %hhd or %hhx
17-
unsigned char %hhu or %hhx
18-
short int %hd or %hx
19-
unsigned short int %hu or %hx
16+
char %d or %x
17+
unsigned char %u or %x
18+
short int %d or %x
19+
unsigned short int %u or %x
2020
int %d or %x
2121
unsigned int %u or %x
2222
long %ld or %lx
@@ -25,10 +25,10 @@ Integer types
2525
unsigned long long %llu or %llx
2626
size_t %zu or %zx
2727
ssize_t %zd or %zx
28-
s8 %hhd or %hhx
29-
u8 %hhu or %hhx
30-
s16 %hd or %hx
31-
u16 %hu or %hx
28+
s8 %d or %x
29+
u8 %u or %x
30+
s16 %d or %x
31+
u16 %u or %x
3232
s32 %d or %x
3333
u32 %u or %x
3434
s64 %lld or %llx

0 commit comments

Comments
 (0)