Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > is a char promoted to an integer in C++?

Reply
Thread Tools

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

 
 
jimjim
Guest
Posts: n/a
 
      09-15-2005
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


 
Reply With Quote
 
 
 
 
Zara
Guest
Posts: n/a
 
      09-15-2005
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.


 
Reply With Quote
 
 
 
 
Jack Klein
Guest
Posts: n/a
 
      09-16-2005
On Thu, 15 Sep 2005 07:46:53 GMT, "jimjim" <(E-Mail Removed)>
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/~a...FAQ-acllc.html
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can characters ever be promoted to 'unsigned int'? chrisbazley@bigfoot.com C Programming 4 03-06-2010 02:22 PM
(const char *cp) and (char *p) are consistent type, (const char **cpp) and (char **pp) are not consistent lovecreatesbeauty C Programming 1 05-09-2006 08:01 AM
/usr/bin/ld: ../../dist/lib/libjsdombase_s.a(BlockGrouper.o)(.text+0x98): unresolvable relocation against symbol `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostre silverburgh.meryl@gmail.com C++ 3 03-09-2006 12:14 AM
char->integer, integer->char commands christophergraber@gmail.com Perl Misc 5 11-22-2005 07:13 AM
Web Server Promoted To Domain Controller cksanjose@gmail.com ASP .Net 1 11-08-2005 10:49 PM



Advertisments