public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] use %p for pointers
@ 2006-10-10 21:49 Al Viro
  2006-10-10 21:58 ` David Miller
  2006-10-11 11:16 ` Jan Engelhardt
  0 siblings, 2 replies; 15+ messages in thread
From: Al Viro @ 2006-10-10 21:49 UTC (permalink / raw)
  To: torvalds; +Cc: linux-kernel


Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
 drivers/sbus/char/uctrl.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/sbus/char/uctrl.c b/drivers/sbus/char/uctrl.c
index ddc0681..b30372f 100644
--- a/drivers/sbus/char/uctrl.c
+++ b/drivers/sbus/char/uctrl.c
@@ -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;
-- 
1.4.2.GIT


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [PATCH] use %p for pointers
  2006-10-10 21:49 [PATCH] use %p for pointers Al Viro
@ 2006-10-10 21:58 ` David Miller
  2006-10-11 11:16 ` Jan Engelhardt
  1 sibling, 0 replies; 15+ messages in thread
From: David Miller @ 2006-10-10 21:58 UTC (permalink / raw)
  To: viro; +Cc: torvalds, linux-kernel

From: Al Viro <viro@ftp.linux.org.uk>
Date: Tue, 10 Oct 2006 22:49:57 +0100

> 
> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

Signed-off-by: David S. Miller <davem@davemloft.net>

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] use %p for pointers
  2006-10-10 21:49 [PATCH] use %p for pointers Al Viro
  2006-10-10 21:58 ` David Miller
@ 2006-10-11 11:16 ` Jan Engelhardt
  2006-10-11 14:54   ` Al Viro
  1 sibling, 1 reply; 15+ messages in thread
From: Jan Engelhardt @ 2006-10-11 11:16 UTC (permalink / raw)
  To: Al Viro; +Cc: torvalds, linux-kernel


>diff --git a/drivers/sbus/char/uctrl.c b/drivers/sbus/char/uctrl.c
>index ddc0681..b30372f 100644
>--- a/drivers/sbus/char/uctrl.c
>+++ b/drivers/sbus/char/uctrl.c
>@@ -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'
-- 

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] use %p for pointers
  2006-10-11 11:16 ` Jan Engelhardt
@ 2006-10-11 14:54   ` Al Viro
  2006-10-11 18:45     ` H. Peter Anvin
  0 siblings, 1 reply; 15+ messages in thread
From: Al Viro @ 2006-10-11 14:54 UTC (permalink / raw)
  To: Jan Engelhardt; +Cc: torvalds, linux-kernel

On Wed, Oct 11, 2006 at 01:16:56PM +0200, Jan Engelhardt wrote:
> 
> >diff --git a/drivers/sbus/char/uctrl.c b/drivers/sbus/char/uctrl.c
> >index ddc0681..b30372f 100644
> >--- a/drivers/sbus/char/uctrl.c
> >+++ b/drivers/sbus/char/uctrl.c
> >@@ -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).

%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...

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] use %p for pointers
  2006-10-11 14:54   ` Al Viro
@ 2006-10-11 18:45     ` H. Peter Anvin
  2006-10-11 19:13       ` Jan Engelhardt
                         ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: H. Peter Anvin @ 2006-10-11 18:45 UTC (permalink / raw)
  To: Al Viro; +Cc: Jan Engelhardt, torvalds, linux-kernel

Al Viro wrote:
> 
> %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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] use %p for pointers
  2006-10-11 18:45     ` H. Peter Anvin
@ 2006-10-11 19:13       ` Jan Engelhardt
  2006-10-11 19:16         ` H. Peter Anvin
  2006-10-11 20:28       ` Jakub Jelinek
  2006-10-12 11:03       ` Nikita Danilov
  2 siblings, 1 reply; 15+ messages in thread
From: Jan Engelhardt @ 2006-10-11 19:13 UTC (permalink / raw)
  To: H. Peter Anvin; +Cc: Al Viro, torvalds, linux-kernel


>> %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 *).

> It's really too bad gcc bitches about %#p, because that's arguably The Right
> Thing.

ack. Make a bug report perhaps?

	-`J'
-- 

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] use %p for pointers
  2006-10-11 19:13       ` Jan Engelhardt
@ 2006-10-11 19:16         ` H. Peter Anvin
  2006-10-11 19:28           ` Jan Engelhardt
  0 siblings, 1 reply; 15+ messages in thread
From: H. Peter Anvin @ 2006-10-11 19:16 UTC (permalink / raw)
  To: Jan Engelhardt; +Cc: Al Viro, torvalds, linux-kernel

Jan Engelhardt wrote:
>>> %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.

>> 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


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] use %p for pointers
  2006-10-11 19:16         ` H. Peter Anvin
@ 2006-10-11 19:28           ` Jan Engelhardt
  0 siblings, 0 replies; 15+ messages in thread
From: Jan Engelhardt @ 2006-10-11 19:28 UTC (permalink / raw)
  To: H. Peter Anvin; +Cc: Al Viro, torvalds, linux-kernel


>> > > %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.

Ah my bad. Thanks for the slap reminder. :)


	-`J'
-- 

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] use %p for pointers
  2006-10-11 18:45     ` H. Peter Anvin
  2006-10-11 19:13       ` Jan Engelhardt
@ 2006-10-11 20:28       ` Jakub Jelinek
  2006-10-11 20:39         ` H. Peter Anvin
  2006-10-12 11:03       ` Nikita Danilov
  2 siblings, 1 reply; 15+ messages in thread
From: Jakub Jelinek @ 2006-10-11 20:28 UTC (permalink / raw)
  To: H. Peter Anvin; +Cc: Al Viro, Jan Engelhardt, torvalds, linux-kernel

On Wed, Oct 11, 2006 at 11:45:10AM -0700, H. Peter Anvin wrote:
> Al Viro wrote:
> >
> >%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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] use %p for pointers
  2006-10-11 20:28       ` Jakub Jelinek
@ 2006-10-11 20:39         ` H. Peter Anvin
  0 siblings, 0 replies; 15+ messages in thread
From: H. Peter Anvin @ 2006-10-11 20:39 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Al Viro, Jan Engelhardt, torvalds, linux-kernel

Jakub Jelinek wrote:
> On Wed, Oct 11, 2006 at 11:45:10AM -0700, H. Peter Anvin wrote:
>> Al Viro wrote:
>>> %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


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] use %p for pointers
  2006-10-11 18:45     ` H. Peter Anvin
  2006-10-11 19:13       ` Jan Engelhardt
  2006-10-11 20:28       ` Jakub Jelinek
@ 2006-10-12 11:03       ` Nikita Danilov
  2006-10-12 11:49         ` Andreas Schwab
  2006-10-15 15:39         ` Jan Engelhardt
  2 siblings, 2 replies; 15+ messages in thread
From: Nikita Danilov @ 2006-10-12 11:03 UTC (permalink / raw)
  To: H. Peter Anvin; +Cc: Jan Engelhardt, torvalds, linux-kernel, Al Viro

H. Peter Anvin writes:
 > Al Viro wrote:
 > > 
 > > %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

Signed-off-by: Nikita Danilov <danilov@gmail.com>

Index: git-linux/lib/vsprintf.c
===================================================================
--- git-linux.orig/lib/vsprintf.c
+++ git-linux/lib/vsprintf.c
@@ -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;
 
 


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] use %p for pointers
  2006-10-12 11:03       ` Nikita Danilov
@ 2006-10-12 11:49         ` Andreas Schwab
  2006-10-12 12:02           ` Nikita Danilov
  2006-10-15 15:39         ` Jan Engelhardt
  1 sibling, 1 reply; 15+ messages in thread
From: Andreas Schwab @ 2006-10-12 11:49 UTC (permalink / raw)
  To: Nikita Danilov
  Cc: H. Peter Anvin, Jan Engelhardt, torvalds, linux-kernel, Al Viro

Nikita Danilov <nikita@clusterfs.com> writes:

> 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.

> it's lib/vsprintf.c to blame for non-conforming behavior.

The standard makes it completely implementation defined.

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
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."

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] use %p for pointers
  2006-10-12 11:49         ` Andreas Schwab
@ 2006-10-12 12:02           ` Nikita Danilov
  2006-10-12 12:33             ` Jan Engelhardt
  0 siblings, 1 reply; 15+ messages in thread
From: Nikita Danilov @ 2006-10-12 12:02 UTC (permalink / raw)
  To: Andreas Schwab
  Cc: H. Peter Anvin, Jan Engelhardt, torvalds, linux-kernel, Al Viro

Andreas Schwab writes:
 > Nikita Danilov <nikita@clusterfs.com> writes:
 > 
 > > 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.
 > 
 > > it's lib/vsprintf.c to 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.

 > 
 > Andreas.

Nikita.


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] use %p for pointers
  2006-10-12 12:02           ` Nikita Danilov
@ 2006-10-12 12:33             ` Jan Engelhardt
  0 siblings, 0 replies; 15+ messages in thread
From: Jan Engelhardt @ 2006-10-12 12:33 UTC (permalink / raw)
  To: Nikita Danilov
  Cc: Andreas Schwab, H. Peter Anvin, torvalds, linux-kernel, Al Viro

> > > 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.
> > 
> > > it's lib/vsprintf.c to 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'
-- 

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] use %p for pointers
  2006-10-12 11:03       ` Nikita Danilov
  2006-10-12 11:49         ` Andreas Schwab
@ 2006-10-15 15:39         ` Jan Engelhardt
  1 sibling, 0 replies; 15+ messages in thread
From: Jan Engelhardt @ 2006-10-15 15:39 UTC (permalink / raw)
  To: Nikita Danilov
  Cc: H. Peter Anvin, torvalds, Linux Kernel Mailing List, Al Viro


>so %p already has to output '0x', it's lib/vsprintf.c to blame for
>non-conforming behavior. What about
>
>Signed-off-by: Nikita Danilov <danilov@gmail.com>
>
>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)
Signed-off-by: Jan Engelhardt <jengelh@gmx.de>


	-`J'
-- 

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2006-10-15 15:43 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-10-10 21:49 [PATCH] use %p for pointers Al Viro
2006-10-10 21:58 ` David Miller
2006-10-11 11:16 ` Jan Engelhardt
2006-10-11 14:54   ` Al Viro
2006-10-11 18:45     ` H. Peter Anvin
2006-10-11 19:13       ` Jan Engelhardt
2006-10-11 19:16         ` H. Peter Anvin
2006-10-11 19:28           ` Jan Engelhardt
2006-10-11 20:28       ` Jakub Jelinek
2006-10-11 20:39         ` H. Peter Anvin
2006-10-12 11:03       ` Nikita Danilov
2006-10-12 11:49         ` Andreas Schwab
2006-10-12 12:02           ` Nikita Danilov
2006-10-12 12:33             ` Jan Engelhardt
2006-10-15 15:39         ` Jan Engelhardt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox