libc/printf bug



The following code exhibits unexpected behavior. Either it's
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?

[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]$

.



Relevant Pages

  • Re: libc/printf bug
    ... or the author is blind as a bat. ... Am I missing ... I don't see that the cast should have any effect at all ... How would you print a float in hex? ...
    (comp.os.linux.development.apps)
  • Re: Elections
    ... it is okay for those who are not blind to have the right to cast our ... > Everybody should have the right to cast their ballot in secret. ... > problem is that voting machines don't make that possible. ... to cast a secret ballot, cast a secret ballot if we applied the ...
    (soc.retirement)
  • Re: caste Q
    ... int mainis better style, ... Provide prototypes for your ... Missing (NULL, and IIRC also a missing prototype for 'time'. ... Lose the spurious cast. ...
    (comp.lang.c)
  • Re: Specify member scope in Interface Classes
    ... Yes, you are correct, I could cast the object and access the methods ... but I think you are missing my point. ... Microsoft achieved the ... interface to be able to override that functionality? ...
    (microsoft.public.dotnet.general)
  • Re: libc/printf bug
    ... I don't see that the cast should have any effect at all ... How would you print a float in hex? ... So seems printf gets confused because you present it with a float when i t wants an integer. ... This behavior I have seen in other cases where wrong or missing arguments were presented too. ...
    (comp.os.linux.development.apps)