Octal integer literals #7886
Unanswered
colejohnson66
asked this question in
Language Ideas
Replies: 3 comments 3 replies
-
I remember this coming up during the discussion around binary literals but I don't see it mentioned in any of the meeting notes. |
Beta Was this translation helpful? Give feedback.
1 reply
-
Why not 0C/0c? |
Beta Was this translation helpful? Give feedback.
2 replies
-
Group separated binary literal can somehow solve it. For example, |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Sometimes, when writing P/Invoke code, we encounter enum-like constants that are written in C using octal literals. For example, from
<bits/poll.h>
in glibc,POLLERR
,POLLHUP
, andPOLLNVAL
are written using C's octal literal notation (prefixed by a lone zero). These can be translated into C# by writing their equivalent decimal, hexadecimal, or binary value, but this is error-prone.I propose that C# support octal literals, but with a caveat. In C, it is widely considered a mistake that any zero-prefixed number is octal. Instead, we should require a
0o
or0O
(U+0030 DIGIT ZERO
followed by either aU+004F LATIN CAPITAL LETTER O
orU+006F LATIN SMALL LETTER O
) prefix, similar to hexadecimal. There is some precedent for this from multiple languages:As with other integer literals, underscore-based separators would be allowed.
The language grammar would be altered as follows:
Alternatively, a different letter can be chosen to avoid visual collision between
U+0030 DIGIT ZERO
andU+004F LATIN CAPITAL LETTER O
. NASM resolves this potential issue by also allowingU+0072 LATIN SMALL LETTER Q
as a separator, but this could cause confusion.Beta Was this translation helpful? Give feedback.
All reactions