Thoughts on unified integer literal improvements

Alex Buckley Alex.Buckley at Sun.COM
Mon Jun 29 11:32:03 PDT 2009


Hi Bruce,

Bruce Chapman wrote:
> My preference at the moment is for the "u" suffix with autosizing 
> semantics.

Just as well, since a new unsigned primitive type in the JLS is not on 
the table in Coin.

> Some work is needed to define the autosizing rules exactly - I am 
> currently leaning toward (loosely)
> 
>    The type of the literal  is the smallest integral type capable of 
> holding all significant bits of the constant, unless the first
>    digit of the literal (excluding prefix characters) is '0' in which 
> case the type is the smallest integral type capable of holding one more 
> than the number of significant bits of the constant value. eg 0xFFu is 
> byte, 0x0FFu is short.

I personally tend to shy away from 'correct but clever' rules that make 
the reader work hard to follow the types.

> 1) "unsigned int" needs JLS changes that are excessive comparative to 
> their value, when compared to the other options.
> 
> 2) Having a new primitive type "unsigned int" which can only be used for 
> literals, and cannot be used to declare variables has a high probability 
> of being viewed negatively by the user community. Some users would wish 
> for full unsigned support, and others would wish that it wasn't there at 
> all. The effort cost of explaining this afterwards will be significant

Thumbs up so far!

> 3) Explicit use of leading '0' digit in autosizing case to force zero 
> extension is a good thing.
> 
> 4) One way to deal with the octal literal vs leading zero widens 
> conflict would be to introduce alternate alphabetic prefixes for decimal 
> (d) and octal (o) eg 0d10 (10) and 0o10 (8) which could be used in 
> combination with a leading 0 digit to force zero extend (eg 0d0255u is 
> short value 255)- however I assume this is unjustifiable complexity.

Unjustifiable, correct. Triggering autosizing with a leading 0 almost 
seems like a clash for the sake of it! Keep autosizing out unless 
experience with prototypes shows that the other integer literal 
improvements are worthless without it.

Alex



More information about the coin-dev mailing list