0nnn octal notation considered harmful

Steven Schveighoffer schveiguy at yahoo.com
Mon Feb 14 07:22:07 PST 2011


On Fri, 11 Feb 2011 17:52:34 -0500, Tomek Sowiński <just at ask.me> wrote:

> spir napisał:
>
>> Just had a strange bug --in a test func!-- caused by this notation.  
>> This is due
>> in my case to the practice (common, I guess) of "pretty printing" int  
>> numbers
>> using %0nd or %0ns format, to get a nice alignment. Then, if one feeds  
>> back
>> results into D code, they are interpreted as octal...
>> Now, i know it: will pad with spaces instead ;-)
>>
>> Copying a string'ed integer is indeed not the only this notation is  
>> bug-prone:
>> prefixing a number with '0' should not change its value (!). Several
>> programming languages switched to another notation; like 0onnn, which is
>> consistent with common hex & bin notations and cannot lead to
>> misinterpretation. Such a change would be, I guess, backward  
>> compatible; and
>> would not be misleading for C coders.
>
> This has been discussed before. There's octal!123 in Phobos if you don't  
> like these confusing literals but they stay because Walter likes them.
>

I think the point is he *doesn't* want to use octal literals.

-Steve


More information about the Digitalmars-d mailing list