excessively long integer literal

Ap Lee aplee at primus.ca
Sun Jan 6 20:24:38 PST 2008


Hello,

I am trying to build some template struct for large integer values, and I 
realized there is something weird with the lexical interpretation of 
integer literals.

I have this code instantiating a LargeInt struct which, in this example, 
has a capacity of 256 bits:

   LargeInt!(256) v = 0xFFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF;

Under the hood, this assignment uses the opAssign overload I created for 
ulong. Obviously, ulong is only 64 bits in size, and only the lowest 64 
bits of the "v" variable get set to 1, while the upper bits remain at 0.

But there is something wrong. The compiler accepted this code, and it's 
silently wrong at runtime... I think the compiler should have rejected the 
integer literal.

What do you think?

Ap


More information about the Digitalmars-d-learn mailing list