Search code examples
cstructqemubit-fields

What does : mean in C?


While looking through the source package for QEMU, I found in the exec.c file:

struct PhysPageEntry {
    /* How many bits skip to next level (in units of L2_SIZE). 0 for a leaf. */
    uint32_t skip : 6;
     /* index into phys_sections (!skip) or phys_map_nodes (skip) */
    uint32_t ptr : 26;
};

I was wondering what the : operator means. I could not find it in a list of syntax definitions for C.


Solution

  • This is a structure declared with bit fields and the structure members are called bit fields: A bit field is set up with a structure declaration that labels each field and determines its width. The above definition causes PhysPageEntry to contain one 6-bit field and one 26 bit field members namely skip and ptr respectively. Its signature is

    struct
    {
          type [member_name] : width ;
    };  
    

    Here width is the number of bits in the bit-field. The width must be less than or equal to the bit width of the specified type.