www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8474] New: bitfields doesn't work with bitfield over 31 bits

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8474

           Summary: bitfields doesn't work with bitfield over 31 bits
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: andrej.mitrovich gmail.com



11:01:59 PDT ---
import std.bitmanip;
struct Foo
{
    mixin(bitfields!(
        uint, "bits1", 32,
    ));
}

void main() { }

std\bitmanip.d(76): Error: shift by 32 is outside the range 0..31

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 30 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8474


monarchdodra gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |monarchdodra gmail.com



FYI: Bitfileds DO work with fields over 32. They just don't work for fields
that are EXACTLY 32.

The problem is that since the field is 32 bits long, it is placed in a uint.
When trying to create the "signed mask" though the "1" is attempted to be
placed at index 32 (1 << 32), which becomes illegal.

The problem does not appear if the field is SMALLER than 32, since the mask
will fit.
The problem does not appear if the field is BIGGER than 32, the type will be
placed in a ulong.

Oh yeah, and fields that are exactly 64 bits long don't work either. This is
arguably less of a problem though... but still wrong.

=>Changing title

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 31 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8474




More details: The problem only appears if the 32 (64) bit field is aligned with
0.

THIS will not create a bug:

--------
import std.bitmanip;
struct A
{
    mixin(bitfields!(
        uint, "a",  1,
        uint, "b", 32,
        uint, "c", 31,)
    );
}
void main()
{
  A a;
};

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 31 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8474


Era Scarecrow <rtcvb32 yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|                            |rtcvb32 yahoo.com
         AssignedTo|nobody puremagic.com        |rtcvb32 yahoo.com



---
My current branch resolves this issue. Once the pull is accepted this will be
resolved.

https://github.com/rtcvb32/phobos/commit/620ba57cc0a860245a2bf03f7b7f5d6a1bb58312

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 01 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8474


David Nadlinger <code klickverbot.at> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
                 CC|                            |code klickverbot.at
         Resolution|                            |FIXED



PDT ---
https://github.com/D-Programming-Language/phobos/pull/1613

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