is a char promoted to an integer in C++?

Discussion in 'C++' started by jimjim, Sep 15, 2005.

  1. jimjim

    jimjim Guest

    Hello all,

    Is a char promoted to an integer in C++ in order to make lets say an
    addition?

    STD C: 5.1.2.3/10:
    In executing the fragment
    char c1, c2;
    /* ... */
    c1 = c1 + c2;
    the ''integer promotions'' require that the abstract machine promote the
    value of each variable to int size and then add the two ints and truncate
    the sum.

    TIA
    jimjim, Sep 15, 2005
    #1
    1. Advertising

  2. jimjim

    Zara Guest

    jimjim wrote:
    > Hello all,
    >
    > Is a char promoted to an integer in C++ in order to make lets say an
    > addition?
    >
    > STD C: 5.1.2.3/10:
    > In executing the fragment
    > char c1, c2;
    > /* ... */
    > c1 = c1 + c2;
    > the ''integer promotions'' require that the abstract machine promote the
    > value of each variable to int size and then add the two ints and truncate
    > the sum.
    >
    > TIA
    >
    >

    Yes, it is so. Some compilers may warn you of the loss of precision
    implied in c1 = c1 + c2;
    Using c1+=c2 there is neither such promotion no such warning.
    Zara, Sep 15, 2005
    #2
    1. Advertising

  3. jimjim

    Jack Klein Guest

    On Thu, 15 Sep 2005 07:46:53 GMT, "jimjim" <>
    wrote in comp.lang.c++:

    > Hello all,
    >
    > Is a char promoted to an integer in C++ in order to make lets say an
    > addition?
    >
    > STD C: 5.1.2.3/10:
    > In executing the fragment
    > char c1, c2;
    > /* ... */
    > c1 = c1 + c2;
    > the ''integer promotions'' require that the abstract machine promote the
    > value of each variable to int size and then add the two ints and truncate
    > the sum.
    >
    > TIA


    Yes, as far as the abstract machine is concerned. The "as-if" rule
    allows an implementation to skip the actual up and down conversion if
    and only if it can produce the same result.

    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
    comp.lang.c++ http://www.parashift.com/c -faq-lite/
    alt.comp.lang.learn.c-c++
    http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
    Jack Klein, Sep 16, 2005
    #3
    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. Replies:
    1
    Views:
    398
    Juan T. Llibre
    Nov 8, 2005
  2. lovecreatesbeauty
    Replies:
    1
    Views:
    1,012
    Ian Collins
    May 9, 2006
  3. Replies:
    4
    Views:
    438
    Tim Rentsch
    Mar 6, 2010
  4. Replies:
    5
    Views:
    217
    Tassilo v. Parseval
    Nov 22, 2005
  5. John Reye
    Replies:
    16
    Views:
    687
    Tim Rentsch
    Jun 23, 2012
Loading...

Share This Page