possible printf error

Steven J Abner tauvan@starpower.net
Mon Nov 15 20:43:00 GMT 2004

   First, I am on a system which I believe uses an earlier version of 
newlibc. I've
encountered an oddity which may?? be an issue.
   The use of "printf("%#.6x", 0);" produces "000000". Which, by the IEEE 
definition of
the '#' flag states: "For x or X conversion specifiers, a non-zero 
result shall have
0x (or 0X) prefixed to it.",  is correct. However, in a series of hex(s) 
with a variable
input rather than an explicit "0", if one is expecting to have an 
implicit field width
of 8, ie 0x000030, 0x000100, 0x000000...., or a hex with a 0x prefix 
when "0" occurs,
you have to test for 0 and issue "printf("%s", "0x");""printf("%#.6x", 
   I may have missed the point of a '#' flag, but I thought this 
incorrect in spite of the
definition. I can see where "printf("%#.0x", 0);" should drop "0x" but 
why "%#x"?

   Well, food for thought.
      Steve @<tauvan@starpower.net>

PS. Have a couple of others, and would like to know if there is a 
discussion bb address
to query, rather than this bug reporting address?

More information about the Newlib mailing list