Thread overview
Way to express bitfields?
Mar 19, 2003
Steve Adams
Mar 19, 2003
Burton Radons
Mar 19, 2003
DDevil
March 19, 2003
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?



March 19, 2003
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.

March 19, 2003
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