Literals starting with 0 will not work with UFCS

Jonathan Andrew jonfandrew at gmail.com
Wed Jul 4 16:44:19 PDT 2012


On Wednesday, 4 July 2012 at 00:34:39 UTC, Jonathan M Davis wrote:
> On Wednesday, July 04, 2012 02:20:26 ixid wrote:
>> 0.writeln();
>
> This works.
>
>> 01.writeln();
>
> This doesn't.
>
>> etc...
>> 
>> Throw up a series of errors while any other number as the 
>> leading
>> digit seems to work fine. Why is this?
>
> It's probably an artifact of getting rid of octal literals and 
> is clearly a
> bug - though you probably shouldn't be starting literals with 0 
> due to
> possible confusion with octal literals anyway (00 - 07 are 
> permitted because
> they're the same in both octal and decimal, but any other 
> number literal
> starting with 0 is illegal).
>
> The error you get for something like
>
> auto n = 08;
>
> is a bit off too
>
> q.d(5): Error: semicolon expected following auto declaration, 
> not '8'
>
> - Jonathan M Davis

The one exception I found to starting literals with 0 is when 
using dates - using the DateTime module (excellent write-up, 
btw!) and having to pass dates like 07/04/09 as 7, 4, 9 without 
the leading 0 is kind of awkward, for me at least. Minor gripe.


More information about the Digitalmars-d-learn mailing list