Re: libc/printf bug
- From: Micah Cowan <micah@xxxxxxxxxx>
- Date: Tue, 28 Feb 2006 21:29:28 GMT
"Nils O. Selåsdal" <NOS@xxxxxxx> writes:
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.
This isn't actually true: it will do exactly the same promotions to
printf()s arguments as /already/ occur when calling printf().
Calling it without a prototype in scope will cause gcc to complain
that the implicit declaration of printf() is incompatible with its
actual prototype, but it apparently still works as expected; however,
as far as the C standard is concerned, its behavior is undefined. This
means that
(a) it could break on other systems besides Linux/glibc systems, and
(b) it may break on future versions of Linux/glibc, as they will not
feel obliged to continue to support this incorrect usage.
.
- Follow-Ups:
- Re: libc/printf bug
- From: Måns Rullgård
- Re: libc/printf bug
- References:
- libc/printf bug
- From: bill pursell
- Re: libc/printf bug
- From: "Nils O. Selåsdal"
- libc/printf bug
- Prev by Date: Re: Trolltech QT license question
- Next by Date: Re: Trolltech QT license question
- Previous by thread: Re: libc/printf bug
- Next by thread: Re: libc/printf bug
- Index(es):
Relevant Pages
|