Promotion and assignment

Discussion in 'C Programming' started by Tomás Ó hÉilidhe, Jul 9, 2008.

  1. Take the following:

    char unsigned i = 0, j = 5;
    ...
    ...
    i &= j;

    I'd like to see what happens in the last statement. If it were
    identical to:

    i = i & j;

    then the follwoing would happen:
    * On the right-hand side, both i and j would be promoted to either
    signed int or unsigned int
    * The bitwise AND would be performed on these two int's
    * Then the result would be converted to an unsigned char to be stored
    in i

    Does exactly the same thing happen with i &= j?
     
    Tomás Ó hÉilidhe, Jul 9, 2008
    #1
    1. Advertisements

  2. Tomás Ó hÉilidhe

    Guest

    On Jul 9, 4:11 pm, Tomás Ó hÉilidhe <> wrote:
    > Take the following:
    >
    > char unsigned i = 0, j = 5;
    > ...
    > ...
    > i &= j;
    >
    > I'd like to see what happens in the last statement. If it were
    > identical to:
    >
    > i = i & j;
    >
    > then the follwoing would happen:
    > * On the right-hand side, both i and j would be promoted to either
    > signed int or unsigned int

    Don't you mean int unsigned? :)

    > * The bitwise AND would be performed on these two int's
    > * Then the result would be converted to an unsigned char to be stored
    > in i
    >
    > Does exactly the same thing happen with i &= j?

    Yes, for the long answer see Mr Sosmans post.
     
    , Jul 10, 2008
    #2
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jon Paul Jones

    ASP.NET, source safe and promotion levels

    Jon Paul Jones, Jan 19, 2005, in forum: ASP .Net
    Replies:
    8
    Views:
    553
    Rusty Zarse
    Feb 8, 2005
  2. =?ISO-8859-1?Q?Christian_Brechb=FChler?=

    Arithmetic conversions/promotion and templates

    =?ISO-8859-1?Q?Christian_Brechb=FChler?=, Oct 19, 2003, in forum: C++
    Replies:
    3
    Views:
    618
    =?ISO-8859-1?Q?Christian_Brechb=FChler?=
    Oct 20, 2003
  3. BCC

    Casting and promotion

    BCC, May 2, 2005, in forum: C++
    Replies:
    3
    Views:
    493
    Peter Koch Larsen
    May 4, 2005
  4. nagy
    Replies:
    36
    Views:
    1,444
    Terry Reedy
    Jul 20, 2006
  5. Russell Shaw

    Integer promotion and overflow

    Russell Shaw, Jan 2, 2005, in forum: C Programming
    Replies:
    20
    Views:
    1,383
    Keith Thompson
    Jan 3, 2005
  6. Carsten Hansen

    Bit-fields and integral promotion

    Carsten Hansen, Jan 28, 2005, in forum: C Programming
    Replies:
    117
    Views:
    2,330
    Joe Wright
    Feb 8, 2005
  7. Christian Kandeler

    Bit-fields and integral promotion/UACs

    Christian Kandeler, Jan 27, 2006, in forum: C Programming
    Replies:
    10
    Views:
    864
    Alex Fraser
    Jan 28, 2006
  8. Chris
    Replies:
    34
    Views:
    2,170
Loading...