[Issue 1773] New: excessively long integer literal

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jan 7 21:14:51 PST 2008


http://d.puremagic.com/issues/show_bug.cgi?id=1773

           Summary: excessively long integer literal
           Product: D
           Version: 1.020
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: aplee at primus.ca


An excessively long integer literal is accepted by the compiler, as show in
this simple example, where a LargeInt struct instance is declared with 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. Also obvious is
that a 256-bit integer literal is not supposed to be supported. The prioblem is
that this code is accepted by the compiler, leading to beleive that all 256
bits are set to 1 when in reality they aren't.

I experimented a little bit and found that 0xf_ffff_ffff_ffff_ffff also
compiled, but 0x1_0000_0000_0000_0000 did not compile.

This is with gdc 0.24, using dmd 1.020


-- 



More information about the Digitalmars-d-bugs mailing list