Thoughts on unified integer literal improvements
Joe Darcy
Joe.Darcy at Sun.COM
Wed May 27 15:56:51 PDT 2009
Hello.
On the set of improved integer literal features, I think combining the
underscores as separators and binary literals is straightforward given
separately correct grammars for each change.
As an alternate to "y" and "s" suffices, I suggesting considering a "u"
suffix to mean unsigned. Literals with a trailing "u" would have type
int; widening conversions of such literals would 0 extend and narrowing
conversions would range check on the width of set bits. For example,
byte b = 0xABu // equivalent to (0xAB & 0xFF)
long ell = 0xFFFFFFFFu; // A positive long value
I think this approach has some advantages over the "y" suffix; in
particular I think it gives more desirable behavior in cases like this:
byte b = 0xFFy // a negative byte value
byte b = 0xFFu // also a negative byte value
short s = 0xFFy // a negative short value, -128;
// byte value is signed extended
short s = 0xFFu // a positive short value, +127
int i = 0xFFy // -128
int i = 0xFFu // 127
-Joe
More information about the coin-dev
mailing list