Re: libc/printf bug
- From: "Nils O. Selåsdal" <NOS@xxxxxxx>
- Date: Tue, 28 Feb 2006 08:37:29 +0100
bill pursell wrote:
The following code exhibits unexpected behavior. Either it'sThere are quite a few errors in this code.
a bug in libc, or the author (me) is blind as a bat. Am I missing
something here, or is something horribly wrong? It appears
that printf is mangling the address unless the second argument
gets cast. I don't see that the cast should have any effect at all
on the output. Any thoughts?
libc is not at fault.
1. Forgot to include <stdio.h>, this is important so
you get a proper prototye for printf, else the compiler
assumes all arguments are int - and who knows what happens
when it itsn't so, and the compiler generates wrong code
accroding to what you intended.
2. %x are not for printing floats.
[tmp]$ cat printf_bug.c
int
main()
{
float a=0;
printf("%p\n", &a);
printf("%x %p\n", a, &a);
printf("%x %p\n", (int)a, &a);
}
[tmp]$ ./a.out
0xfefb6764
0 (nil)
0 0xfefb6764
[tmp]$
--
Nils O. Selåsdal
www.utelsystems.com
.
- Follow-Ups:
- Re: libc/printf bug
- From: Micah Cowan
- Re: libc/printf bug
- References:
- libc/printf bug
- From: bill pursell
- libc/printf bug
- Prev by Date: Drag from KDE window and drop into GTK one: how ?
- Next by Date: Re: prevent multiple start of app
- Previous by thread: Re: libc/printf bug
- Next by thread: Re: libc/printf bug
- Index(es):
Relevant Pages
|