Announcement

Collapse
No announcement yet.

C Bitfields

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Mark Newman
    replied
    Thanks Tom!

    ------------------
    Mark Newman

    Leave a comment:


  • Tom Hanlin
    replied
    Looks good to me.

    ------------------
    Tom Hanlin
    PowerBASIC Staff

    Leave a comment:


  • Mark Newman
    started a topic C Bitfields

    C Bitfields

    I have a a C bifield to port:
    Code:
    typedef struct BIT_FIELD_STRUCT
    {
       ULONG b1 : 4;     // bits[3:0]
       ULONG b2 : 4;
       ULONG b3 : 4;
       ULONG b4 : 4;
       ULONG b5 : 4;
       ULONG b6 : 4;
       ULONG b7 : 4;
       ULONG b8 : 4;     // bits[31:28]
    } BIT_FIELD;
    My C book tells me that C compiles bitfields into a contiguous stream of bits
    regardless of the member type declaration, so the port to PB would seem to be:
    Code:
    TYPE BIT_FIELD
       BitField    as DWORD
    END TYPE
    I presume that I port C code like:
    Code:
       ABitField.b1 = 0x09
    over to PB as:
    Code:
       ABitField.BitField = ABitField.BitField AND &HFFFFFFF0   ' Clear the lowest 4 bits
       ABitField.BitField = ABitField.BitField OR &H09          ' Set the lower 4 bits to the new value
    Look right?

    Thanks!

    ------------------
    Mark Newman

    [This message has been edited by Mark Newman (edited May 01, 2001).]
Working...
X