www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4425] New: More bells & whistles for bitfields

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

           Summary: More bells & whistles for bitfields
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc


--- Comment #0 from bearophile_hugs eml.cc 2010-07-04 12:39:29 PDT ---
When bit fields are used to define bit protocols etc., they sometimes have
constant fields, or already initialized variable fields. So It can be positive
for std.bitmanip.bitfields to support that too, this is an example:

          field1 : 1;
          field2 : 2 = 0b01;
immutable field3 : 3;
immutable field4 : 4 = 0b1110;


As with normal immutable fields in structs, the language has to forbid the
write on immutable fields. Probably in many cases the compiler can't enforce
this at compile time on bit fields (because of the type system granularity;
something similar happens with pointers to single bits in bit-arrays), so
probably the bit field immutability needs to be enforced at run-time (maybe
even in release mode too, because it's a hard constraint).

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



--- Comment #1 from bearophile_hugs eml.cc 2010-09-24 18:47:19 PDT ---
See also bug 4937

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 24 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4425



--- Comment #2 from bearophile_hugs eml.cc 2010-10-04 18:16:44 PDT ---
Another possible feature is to make std.bitmanip.bitfields generate two
versions of the code, that get compiled conditionally according to the CPU
endianess:


static if (std.system.endian == std.system.Endian.BigEndian) {
    ...
} else {
    ...
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 04 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4425


Era Scarecrow <rtcvb32 yahoo.com> changed:

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


--- Comment #3 from Era Scarecrow <rtcvb32 yahoo.com> 2012-08-02 22:02:41 PDT
---
Adding const to a field seems pretty easy; specifically the setter is simply
left out of the template. So as a final proposed usage, it would look like:

 mixin(bitfields(
          int,  "named",           4,
    const int,  "c_named",         4,
          uint, "named_def=5",     4,    //includes defaulted value of 5
    const uint, "c_named_def=10",  4));  //defaulted value of 10


 bitfieldsOn is being worked on, and effectively works identically to bitfields
except you specify a variable you want to use; Default values won't work well
with it however.

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



--- Comment #4 from bearophile_hugs eml.cc 2012-08-03 03:06:07 PDT ---
(In reply to comment #3)
 Adding const to a field seems pretty easy; specifically the setter is simply
 left out of the template.
OK.
 So as a final proposed usage, it would look like:
 
  mixin(bitfields(
           int,  "named",           4,
     const int,  "c_named",         4,
           uint, "named_def=5",     4,    //includes defaulted value of 5
     const uint, "c_named_def=10",  4));  //defaulted value of 10
Good. And what do you think about facing the endianess problems (Comment 2)?
  bitfieldsOn is being worked on, and effectively works identically to bitfields
 except you specify a variable you want to use; Default values won't work well
 with it however.
What's bitfieldsOn? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 03 2012