Thread overview
Re: Octal-like integer literals
Feb 11, 2012
H. S. Teoh
Feb 11, 2012
Andrej Mitrovic
Feb 11, 2012
H. S. Teoh
Feb 11, 2012
Timon Gehr
Feb 11, 2012
Andrej Mitrovic
Feb 17, 2012
Walter Bright
Feb 17, 2012
Walter Bright
Feb 17, 2012
Daniel Murphy
Feb 17, 2012
H. S. Teoh
Feb 11, 2012
Jonathan M Davis
February 11, 2012
On Sat, Feb 11, 2012 at 05:37:17PM +0100, Timon Gehr wrote:
> On 02/11/2012 05:00 PM, H. S. Teoh wrote:
> >Alright, I'm plodding along slowly with my D lexer, and I'm running into an interesting case. According to the spec, int literals that begin with '0' are supposed to be octal, with the exception of "0" itself, which is decimal 0. DecimalInteger is defined to begin with a non-zero digit followed by one or more digits (may be zero).
> >
> >So how should the lexer treat a literal like "0800" or "0900"?
> >
> >(Since octal literals are deprecated, I'm leaving them out of my lexer, so should 0800 and 0900 be rejected as invalid?)
[...]
> 
> Octal literals whose value is larger than 7 must be rejected. Octal literals with values up to 7 must be accepted.

Are we still supporting octal literals? They are scheduled to be removed at some point, right? FWIW the online specs have no reference to octal literals although the definitions of octal digits are still there.


T

-- 
There's light at the end of the tunnel. It's the oncoming train.
February 11, 2012
Octals are going away, the use of them in Phobos have been removed and Walter confirmed this too afaik.
February 11, 2012
On Sat, Feb 11, 2012 at 06:48:20PM +0100, Andrej Mitrovic wrote:
> Octals are going away, the use of them in Phobos have been removed and Walter confirmed this too afaik.

So the question is, how will things like "0744" and "098" be interpreted once octals have gone away? Will they still be rejected by the compiler?


T

-- 
Talk is cheap. Whining is actually free. -- Lars Wirzenius
February 11, 2012
On 2/11/12, H. S. Teoh <hsteoh@quickfur.ath.cx> wrote:
> On Sat, Feb 11, 2012 at 06:48:20PM +0100, Andrej Mitrovic wrote:
>> Octals are going away, the use of them in Phobos have been removed and Walter confirmed this too afaik.
>
> So the question is, how will things like "0744" and "098" be interpreted once octals have gone away? Will they still be rejected by the compiler?

module test;

void main()
{
    auto x = 0744;
}

$ dmd test.d
$ test.d(5): octal literals 0744 are deprecated, use std.conv.octal!744 instead

You can only use them with the -d switch.
February 11, 2012
On Saturday, February 11, 2012 10:05:40 H. S. Teoh wrote:
> On Sat, Feb 11, 2012 at 06:48:20PM +0100, Andrej Mitrovic wrote:
> > Octals are going away, the use of them in Phobos have been removed and Walter confirmed this too afaik.
> 
> So the question is, how will things like "0744" and "098" be interpreted once octals have gone away? Will they still be rejected by the compiler?

Almost certainly, because otherwise C/C++ code which is ported to D will silently end up with different semantics if 0744 were treated as 744. And in general, C/C++ code either compiles as D code with the same semantics as it has in C/C++, or it does not compile as D code.

- Jonathan M Davis
February 11, 2012
On 02/11/2012 07:05 PM, H. S. Teoh wrote:
> On Sat, Feb 11, 2012 at 06:48:20PM +0100, Andrej Mitrovic wrote:
>> Octals are going away, the use of them in Phobos have been removed and
>> Walter confirmed this too afaik.
>
> So the question is, how will things like "0744" and "098" be interpreted
> once octals have gone away? Will they still be rejected by the compiler?
>
>
> T
>

Probably yes, except for '0+[1-7]?'.
February 17, 2012
On 2/11/2012 10:43 AM, Andrej Mitrovic wrote:
> You can only use them with the -d switch.

And 0744 will never be valid D code, for the simple reason that code moved over from C would silently break in awful ways.
February 17, 2012
On 2/11/2012 10:43 AM, Andrej Mitrovic wrote:
> $ dmd test.d
> $ test.d(5): octal literals 0744 are deprecated, use std.conv.octal!744 instead

I was inordinately proud of that error message :-)
February 17, 2012
I had a look at moving them from deprecated to error, but druntime uses them extensively in the os headers.  I think we need a better solution than a template in the standard library - you shouldn't need a dependency on phobos to use them, and the compiler shouldn't directly reference anything in the standard library.

"Walter Bright" <newshound2@digitalmars.com> wrote in message news:jhkqsj$30j$2@digitalmars.com...
> On 2/11/2012 10:43 AM, Andrej Mitrovic wrote:
>> $ dmd test.d
>> $ test.d(5): octal literals 0744 are deprecated, use std.conv.octal!744
>> instead
>
> I was inordinately proud of that error message :-)


February 17, 2012
On Fri, Feb 17, 2012 at 05:17:00PM +1100, Daniel Murphy wrote:
> I had a look at moving them from deprecated to error, but druntime uses them extensively in the os headers.  I think we need a better solution than a template in the standard library - you shouldn't need a dependency on phobos to use them, and the compiler shouldn't directly reference anything in the standard library.

So why not make the octal template part of druntime?


--T

> "Walter Bright" <newshound2@digitalmars.com> wrote in message news:jhkqsj$30j$2@digitalmars.com...
> > On 2/11/2012 10:43 AM, Andrej Mitrovic wrote:
> >> $ dmd test.d
> >> $ test.d(5): octal literals 0744 are deprecated, use std.conv.octal!744
> >> instead
> >
> > I was inordinately proud of that error message :-)