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. Advertising

  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. Advertising

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:
    422
    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:
    420
    =?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:
    413
    Peter Koch Larsen
    May 4, 2005
  4. nagy
    Replies:
    36
    Views:
    1,015
    Terry Reedy
    Jul 20, 2006
  5. Chris
    Replies:
    34
    Views:
    1,537
Loading...

Share This Page