www.digitalmars.com         C & C++   DMDScript  

D - Way to express bitfields?

reply "Steve Adams" <adamss ascinet.com> writes:
In D, is there a way to express

typedef struct {
  struct {
    union {
      unsigned long  F1   : 25;
      unsigned long  F2   :  7;
      };
    unsigned long all;
  };
  } Bitfields;

and still have it fit in a single long?
Mar 19 2003
next sibling parent Burton Radons <loth users.sourceforge.net> writes:
Steve Adams wrote:
 In D, is there a way to express
 
 typedef struct {
   struct {
     union {
       unsigned long  F1   : 25;
       unsigned long  F2   :  7;
       };
     unsigned long all;
   };
   } Bitfields;
 
 and still have it fit in a single long?

No.
Mar 19 2003
prev sibling parent "DDevil" <ddevil functionalfuture.com> writes:
On Wed, 19 Mar 2003 10:27:00 -0500, Steve Adams wrote:
 In D, is there a way to express
 
 typedef struct {
   struct {
     union {
       unsigned long  F1   : 25;
       unsigned long  F2   :  7;
       };
     unsigned long all;
   };
   } Bitfields;
 
 and still have it fit in a single long?

Is that written correctly? Why would you have a union of bitfields? The way it's currently written would take more than 4 bytes in C/C++ also. Do you mean: typedef struct { union { struct { unsigned long F1 : 25; unsigned long F2 : 7; }; unsigned long all; }; } Bitfields; ? That only takes the space of one long. -- // DDevil
Mar 19 2003