use %p for pointers
Subsystems (3)
PATCH 1/1 use %p for pointers
--- drivers/sbus/char/uctrl.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/sbus/char/uctrl.c +1 -1
@@ -400,7 +400,7 @@ static int __init ts102_uctrl_init(void) } driver->regs->uctrl_intr =UCTRL_INTR_RXNE_REQ |UCTRL_INTR_RXNE_MSK ; -printk ("uctrl: 0x%x (irq %d)\n" , driver->regs, driver->irq); +printk ("uctrl: 0x%p (irq %d)\n" , driver->regs, driver->irq);uctrl_get_event_status ();uctrl_get_external_status ();return 0 ;
Signature · 1 line
1.4.2.GIT
David Miller
maintainerFrom: Al Viro <[email protected]>
Date: Tue, 10 Oct 2006 22:49:57 +0100
Quoted 2 lines
Signed-off-by Al Viro <[email protected]>
drivers/sbus/char/uctrl.c static int __init ts102_uctrl_init(void) · line 403
Quoted 11 lines
drivers/sbus/char/uctrl.c +1
-1@@ -400,7 +400,7 @@ static int __init ts102_uctrl_init(void) } driver->regs->uctrl_intr =UCTRL_INTR_RXNE_REQ |UCTRL_INTR_RXNE_MSK ; -printk ("uctrl: 0x%x (irq %d)\n" , driver->regs, driver->irq); +printk ("uctrl: 0x%p (irq %d)\n" , driver->regs, driver->irq);
So what's the difference, except that %p will evaluate to (nil) or (null) when the argument is 0 [this is the case with glibc]? That would print 0x(nil).
-`J'
Quoted 8 lines · Jan Engelhardt
Quoted 8 lines
drivers/sbus/char/uctrl.c +0
-0@@ -400,7 +400,7 @@ static int __init ts102_uctrl_init(void) }
Quoted 7 lines
drivers/sbus/char/uctrl.c static int __init ts102_uctrl_init(void) · line 403
Quoted 3 lines
drivers/sbus/char/uctrl.c +1
-1driver->regs->uctrl_intr =UCTRL_INTR_RXNE_REQ |UCTRL_INTR_RXNE_MSK ; -printk ("uctrl: 0x%x (irq %d)\n" , driver->regs, driver->irq); +printk ("uctrl: 0x%p (irq %d)\n" , driver->regs, driver->irq);So what's the difference, except that %p will evaluate to (nil) or (null) when the argument is 0 [this is the case with glibc]? That would print 0x(nil).
%p will do no such thing in the kernel. As for the difference... %x might happen to work on some architectures (where sizeof(void *)==sizeof(int)), but it's not portable _and_ not right. %p is proper C for that...
Quoted 4 lines · Al Viro
%p will do no such thing in the kernel. As for the difference... %x might happen to work on some architectures (where
sizeof(void *)==sizeof(int)), but it's not portable _and_ not right. %p is proper C for that...
It's really too bad gcc bitches about %#p, because that's arguably The Right Thing.
-hpa
Quoted 5 lines
Quoted 5 lines
%p will do no such thing in the kernel. As for the difference... %x might happen to work on some architectures (where
sizeof(void *)==sizeof(int)),
but it's not portable _and_ not right. %p is proper C for that...
Ah I see your point, but then again, %lx could have been used. Unless there is some arch where sizeof(long) != sizeof(void *).
Quoted 2 lines
It's really too bad gcc bitches about %#p, because that's arguably The Right Thing.
ack. Make a bug report perhaps?
-`J'
Quoted 6 lines · Jan Engelhardt
Quoted 4 lines
Quoted 4 lines
%p will do no such thing in the kernel. As for the difference... %x might happen to work on some architectures (where
sizeof(void *)==sizeof(int)),
but it's not portable _and_ not right. %p is proper C for that...Ah I see your point, but then again, %lx could have been used. Unless there is some arch where sizeof(long) !=
sizeof(void *).
That really makes gcc bitch, *and* it's wrong for a whole bunch of reasons.
Quoted 4 lines
Quoted 2 lines
It's really too bad gcc bitches about %#p, because that's arguably The Right Thing.
ack. Make a bug report perhaps?
Maybe. They'll probably say "the C standard says so" :-/
-hpa
Quoted 11 lines
Quoted 9 lines
Quoted 6 lines
Quoted 6 lines
%p will do no such thing in the kernel. As for the difference... %x
might happen to work on some architectures (wheresizeof(void *)==sizeof(int)),
but it's not portable _and_ not right. %p is proper C for that...Ah I see your point, but then again, %lx could have been used. Unless there is some arch where sizeof(long) !=
sizeof(void *).That really makes gcc bitch, *and* it's wrong for a whole bunch of reasons.
Ah my bad. Thanks for the slap reminder. :)
-`J'
Quoted 9 lines · H. Peter Anvin
Quoted 5 lines · Al Viro
%p will do no such thing in the kernel. As for the difference... %x might happen to work on some architectures (where
sizeof(void *)==sizeof(int)),
but it's not portable _and_ not right. %p is proper C for that...It's really too bad gcc bitches about %#p, because that's arguably The Right Thing.
It is correct that gcc warns about %#p, that invokes undefined behavior in ISO C99.
Jakub
Quoted 10 lines · Jakub Jelinek
Quoted 5 lines · H. Peter Anvin
Quoted 3 lines · Al Viro
%p will do no such thing in the kernel. As for the difference... %x might happen to work on some architectures (where
sizeof(void *)==sizeof(int)), but it's not portable _and_ not right. %p is proper C for that...It's really too bad gcc bitches about %#p, because that's arguably The Right Thing.
It is correct that gcc warns about %#p, that invokes undefined behavior in ISO C99.
Yes, it's a bug in the standard.
-hpa
Quoted 8 lines · H. Peter Anvin
Quoted 4 lines · Al Viro
%p will do no such thing in the kernel. As for the difference... %x might happen to work on some architectures (where
sizeof(void *)==sizeof(int)), but it's not portable _and_ not right. %p is proper C for that...It's really too bad gcc bitches about %#p, because that's arguably The Right Thing.
Hm...
man 3 printf:
p The void * pointer argument is printed in hexadeci-
mal (as if by %#x or %#lx).
so %p already has to output '0x', it's lib/vsprintf.c to blame for non-conforming behavior. What about
lib/vsprintf.c +1 -1
@@ -408,7 +408,7 @@ int vsnprintf(char *buf, size_t size, co } str =number (str, end, (unsigned long) va_arg(args, void *), -16 , field_width, precision, flags); +16 , field_width, precision, flags|SPECIAL );continue ;
Quoted 6 lines · Nikita Danilov
man 3 printf:
p The void * pointer argument is printed in hexadeci-
mal (as if by %#x or %#lx).so %p already has to output '0x',
That is an detail of this particular implementation.
Quoted 1 line
it's
lib/vsprintf.cto blame for non-conforming behavior.
The standard makes it completely implementation defined.
Andreas.
Signature · 4 lines
Andreas Schwab, SuSE Labs, [email protected] SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany PGP key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different."
Quoted 7 lines · Andreas Schwab
Quoted 5 lines · Nikita Danilov
man 3 printf:
p The void * pointer argument is printed in hexadeci-
mal (as if by %#x or %#lx).
Quoted 7 lines
Quoted 1 line
so %p already has to output '0x',
That is an detail of this particular implementation.
Quoted 1 line
it's
lib/vsprintf.cto blame for non-conforming behavior.The standard makes it completely implementation defined.
Yes, but POSIX/SUS aside, at least we might make kernel version closer to Linux user-level.
Quoted 2 lines
Andreas.
Nikita.
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
man 3 printf:
p The void * pointer argument is printed in hexadeci-
mal (as if by %#x or %#lx).so %p already has to output '0x',
Quoted 8 lines
Quoted 5 lines
That is an detail of this particular implementation.
Quoted 1 line
it's
lib/vsprintf.cto blame for non-conforming behavior.The standard makes it completely implementation defined.
Yes, but POSIX/SUS aside, at least we might make kernel version closer to Linux user-level.
I do agree.
#include <stdio.h>
int main(void) {
return printf("%p %p\n", main, NULL);
}In glibc will print "0x7555562c (nil)" which seems ok enough.
-`J'
Quoted 7 lines
so %p already has to output '0x', it's
lib/vsprintf.cto blame for non-conforming behavior. What aboutSigned-off-by Nikita Danilov <[email protected]>Index:
git-linux/lib/vsprintf.c
Seems like the mail I wrote did not arrive. In that case, I'll give you an URL: http://jengelh.hopto.org/f/nikita-printf-p.diff.bz2 (compile tested)
-`J'