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

J

jimjim

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
 
Z

Zara

jimjim said:
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.
 
J

Jack Klein

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.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top