Jump to page: 1 2
Thread overview
Octal literals: who uses this?
Mar 14, 2009
Christopher Wright
Mar 14, 2009
Sean Kelly
Mar 14, 2009
Stewart Gordon
Mar 14, 2009
Stewart Gordon
Mar 14, 2009
Walter Bright
Mar 14, 2009
Stewart Gordon
Mar 14, 2009
BCS
Mar 14, 2009
Walter Bright
Mar 17, 2009
Don
Mar 17, 2009
BCS
Mar 17, 2009
Walter Bright
Mar 17, 2009
BCS
Mar 17, 2009
Walter Bright
Mar 17, 2009
BCS
Mar 17, 2009
Walter Bright
Mar 18, 2009
Don
Mar 14, 2009
Christopher Wright
March 14, 2009
I've been looking at dil and lexing D. Lexing character literals and string literals is not quite so easy as I thought it would be, but overall not difficult either.

One thing I'm curious about:
There are three forms of hex literals:
\x: 2 digits
\u: 4 digits
\U: 8 digits

There is one form of octal literal:
\: 1 to 3 digits

Why? With hex literals, each option is a fixed width. That is sensible.

Octal literals aren't necessary with hex literals, but they might be convenient. However, making them variable width seems like it opens up the possibility for obscure bugs. I would not recommend that anyone use octal literals, and I don't think they're an advantage to the language. Even if they were, their current representation is not.

Can we just remove this?
March 14, 2009
Christopher Wright wrote:
> I've been looking at dil and lexing D. Lexing character literals and string literals is not quite so easy as I thought it would be, but overall not difficult either.
> 
> One thing I'm curious about:
> There are three forms of hex literals:
> \x: 2 digits
> \u: 4 digits
> \U: 8 digits
> 
> There is one form of octal literal:
> \: 1 to 3 digits
> 
> Why? With hex literals, each option is a fixed width. That is sensible.
> 
> Octal literals aren't necessary with hex literals, but they might be convenient. However, making them variable width seems like it opens up the possibility for obscure bugs. I would not recommend that anyone use octal literals, and I don't think they're an advantage to the language. Even if they were, their current representation is not.
> 
> Can we just remove this?

All the escaped literals are going away, I believe.
March 14, 2009
On Sat, Mar 14, 2009 at 9:13 AM, Christopher Wright <dhasenan@gmail.com> wrote:
> I've been looking at dil and lexing D. Lexing character literals and string literals is not quite so easy as I thought it would be, but overall not difficult either.
>
> One thing I'm curious about:
> There are three forms of hex literals:
> \x: 2 digits
> \u: 4 digits
> \U: 8 digits
>
> There is one form of octal literal:
> \: 1 to 3 digits
>
> Why? With hex literals, each option is a fixed width. That is sensible.
>
> Octal literals aren't necessary with hex literals, but they might be convenient. However, making them variable width seems like it opens up the possibility for obscure bugs. I would not recommend that anyone use octal literals, and I don't think they're an advantage to the language. Even if they were, their current representation is not.

People use octal?

Agreed.
March 14, 2009
Sean Kelly wrote:
<snip>
> All the escaped literals are going away, I believe.

I think all that's happening there is the removal of escaped characters not enclosed in quotes.

Stewart.
March 14, 2009
Christopher Wright wrote:
<snip>
> Octal literals aren't necessary with hex literals, but they might be convenient. However, making them variable width seems like it opens up the possibility for obscure bugs. I would not recommend that anyone use octal literals, and I don't think they're an advantage to the language. Even if they were, their current representation is not.
> 
> Can we just remove this?

One octal literal is very commonly used: \0.

At least save this one.  Just don't go allowing things like "\012" to mean ['\0', '1', '2'].

Stewart.
March 14, 2009
Christopher Wright wrote:
> Can we just remove this?

The octal literals are done the way C does them. The reason they are there are for when translating C code to D code, obscure bugs are not introduced.
March 14, 2009
Walter Bright wrote:
<snip>
> The octal literals are done the way C does them. The reason they are there are for when translating C code to D code, obscure bugs are not introduced.

How would making them illegal not achieve this aim?

Stewart.
March 14, 2009
Hello Stewart,

> Walter Bright wrote:
> <snip>
>> The octal literals are done the way C does them. The reason they are
>> there are for when translating C code to D code, obscure bugs are not
>> introduced.
>> 
> How would making them illegal not achieve this aim?
> 
> Stewart.
> 

Unless you also drop \0 then any octal literal starting in 0 will get incorrectly lexed.


March 14, 2009
Stewart Gordon wrote:
> Walter Bright wrote:
> <snip>
>> The octal literals are done the way C does them. The reason they are there are for when translating C code to D code, obscure bugs are not introduced.
> 
> How would making them illegal not achieve this aim?

The only point to making them illegal would be to eventually remove them completely, which puts us back to \00 meaning something different in D than in C.
March 14, 2009
Walter Bright wrote:
> Christopher Wright wrote:
>> Can we just remove this?
> 
> The octal literals are done the way C does them. The reason they are there are for when translating C code to D code, obscure bugs are not introduced.

Okay, that makes sense. Removing it would be an option; \0 would have to change to \x00. But it's not a big deal, just an annoying blemish.
« First   ‹ Prev
1 2