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

           Summary: Warn on likely hex literal bug
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nob...@puremagic.com
        ReportedBy: andrej.mitrov...@gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrov...@gmail.com> 2011-07-11 
21:14:05 PDT ---
I think this could be a useful test case for a lint-like tool, and perhaps not
DMD itself. But I'm putting it in bugzilla just so I don't ever forget that I
ran into it:

enum paFloat32 = 0x0000_0001;
enum paInt32 = 0x0000_0002;
enum paInt24 = 0x0000_0004;
enum paInt16 = 0x0000_0008;
enum paInt8 = 0x0000_00100;
enum paUInt8 = 0x0000_0020;
enum paCustomFormat = 0x0001_0000;
enum paNonInterleaved = 0x8000_0000;

Hmm.. all seems fine. Except line 5, there's an extra zero at the end!

The integer value of paInt8 is 256 instead of 16. I've had this bug manifest
itself while translating a C header file. I don't really know how it got there,
I know I've added the underscores after HTOD made a pass over the C header, and
that's where I screwed up and must have added another zero.

There's probably not much to do about this. It's still a valid hex literal, it
doesn't overflow, and the underscores are purely conventional and not something
the compiler forces you to do every 4 spaces. But it caused a bug and it's
worth mentioning. Sorry if this doesn't belong here..

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

Reply via email to