bit fields that do not fit in a built-in type

Discussion in 'C++' started by Angel Tsankov, Mar 16, 2006.

  1. Does the C++ standard define what should happen if the size of int in the following code cannot accommodate the bit field?

    struct bit_fields
    {
    unsigned int digit:17; // int is 16 bits
    };
     
    Angel Tsankov, Mar 16, 2006
    #1
    1. Advertisements

  2. Angel Tsankov

    Kai-Uwe Bux Guest

    The excess bits force are used for padding:

    [9.6/1] A member-declarator of the form

    identifier_opt : constant-expression

    specifies a bit-field; its length is set off from the bit-field name by a
    colon. The bit-field attribute is not part of the type of the class member.
    The constant-expression shall be an integral constant-expression with a
    value greater than or equal to zero. The constant-expression may be larger
    than the number of bits in the object representation (3.9) of the
    bit-field?s type; in such cases the extra bits are used as padding bits and
    do not participate in the value representation (3.9) of the bit-field.
    [...]



    Best

    Kai-Uwe Bux
     
    Kai-Uwe Bux, Mar 16, 2006
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.