binary operators

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • dogbert1793@yahoo.com

    #1

    binary operators

    Consider the code:

    unsigned char uc;
    cout << "sizeof( unsigned char ) = " << sizeof( uc ) << endl;
    cout << "sizeof( ~unsigned char ) = " << sizeof( ~uc ) << endl;

    Why is the output:

    sizeof( unsigned char ) = 1
    sizeof( ~unsigned char ) = 4

    and not

    sizeof( unsigned char ) = 1
    sizeof( ~unsigned char ) = 1

  • Barry

    #2
    Re: binary operators

    dogbert1793@yah oo.com wrote:
    Consider the code:
    >
    unsigned char uc;
    cout << "sizeof( unsigned char ) = " << sizeof( uc ) << endl;
    cout << "sizeof( ~unsigned char ) = " << sizeof( ~uc ) << endl;
    >
    Why is the output:
    >
    sizeof( unsigned char ) = 1
    sizeof( ~unsigned char ) = 4
    >
    and not
    >
    sizeof( unsigned char ) = 1
    sizeof( ~unsigned char ) = 1
    >
    [std--
    4.5 Integral promotions [conv.prom]

    3. An rvalue for an integral bit-field (9.6) can be converted to an
    rvalue of type int if int can represent all
    the values of the bit-field; otherwise, it can be converted to unsigned
    int if unsigned int can represent
    all the values of the bit-field. If the bit-field is larger yet, no
    integral promotion applies to it. If the
    bit-field has an enumerated type, it is treated as any other value of
    that type for promotion purposes.
    --End-std]

    Comment

    Working...