From: Jan Svitok Date: 2006-08-19T02:40:01+09:00 Subject: Re: Bug in sprintf? On 8/18/06, Wes Gamble wrote: > Thanks for the comprehensive response. > > Well, I can't really argue with the C implementation, of course... > > BUT > > it feels like if I declare my intent to interpret the sprintf input as a > _decimal_ number with %d (there's a %o if I wanted octal), that is > should allow for leading zeroes. > > My intent in writing sprintf("%d", '08') is to say take the string 08 > and turn it into the number 8. > > It isn't to say here's an octal number, please convert it to decimal for > me. If I think the string is octal, I'll use %o for that. > > So in the spirit of what the user expects, I still think this smells > bad. > > Feel free to convince me otherwise. > > Thanks again, > Wes > As I see it, there are two separate things: WHAT number you want to print, and HOW you want it print. The latter one is specified by the format string. The former one is specified by argument. Think of sprintf("%d", 0x1234) or sprintf("%x", 123). And it happens to be that '08' is in this case the same as 08 and that is invalid octal number. QED. ;-) Jano