www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Other integral literals?

reply bearophile <bearophileHUGS lycos.com> writes:
Do you ever desire literals for byte, ubyte, short and ushort integrals (beside
the currently present for int, uint, long, ulong that are 10, 10U, 10L, 10UL)?

Because of the more strict typing of templates in some situations I have had to
write things like:

cast(ubyte)100

Possible literals for byte, ubyte, short and ushort integrals (the byte ones
aren't great):
10Y
10UY
10S
10US

Are similar suffixes useful enough to have?

Bye,
bearophile
Mar 20 2011
next sibling parent Kagamin <spam here.lot> writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4870
Mar 20 2011
prev sibling next sibling parent spir <denis.spir gmail.com> writes:
On 03/20/2011 04:40 PM, bearophile wrote:
 Do you ever desire literals for byte, ubyte, short and ushort integrals
(beside the currently present for int, uint, long, ulong that are 10, 10U, 10L,
10UL)?

 Because of the more strict typing of templates in some situations I have had
to write things like:

 cast(ubyte)100

 Possible literals for byte, ubyte, short and ushort integrals (the byte ones
aren't great):
 10Y
 10UY
 10S
 10US

 Are similar suffixes useful enough to have?

I would support this gratefully. I find it a big weakness of D that its literals do not map to a type. As for precise morphology, I'd prefere * instead of cryptic suffixes like 'Y' or 'S', numerous languages simply write the size : 8, 16, 32, 64: much nicer! A better idea would be to count the size in bytes: 1, 2, 4, 8. * else, use lowercase suffixes in std, because digits are full height (so that the suffix is more clearly told apart) * for the same reason, hex literals should use uppercase digits in std and '0x' prefix * ideally, I would use the sign to tell signed types apart (1 is unsigned, +1 is signed) * get rid of "1." and ".1" horrors! * get rif of 01 octal bug! Denis -- _________________ vita es estrany spir.wikidot.com
Mar 20 2011
prev sibling parent "Simen kjaeraas" <simen.kjaras gmail.com> writes:
On Sun, 20 Mar 2011 19:37:45 +0100, spir <denis.spir gmail.com> wrote:

 * ideally, I would use the sign to tell signed types apart (1 is  
 unsigned, +1 is signed)

I hope you messed that one up. An unadorned int literal should be signed. Period.
 * get rid of 01 octal bug!

Oh gods, yes. -- Simen
Mar 20 2011