James Kanze
11/20/2008 10:38:00 AM
On Nov 20, 7:58 am, mail....@gmail.com wrote:
> Consider following:
> unsigned char i= 0;
> Now when we perform "++i" Is "i" typecasted into "int", "++"
> operator increment its value and finally typecasted into
> "unsigned char"?
It depends, sort of. First of all, there's no "typecasting"
involved; typecasting is an explicit conversion, and any
conversions here are implicit. But type promotion will occur;
if an int can represent all possible values of unsigned char,
the unsigned char will be promoted to int; otherwise, it will be
promoted to unsigned int. The arithmetic will be performed on
the promoted type, and the results will be converted to the
target type.
For such simple operations, it doesn't matter, but in more
complicated cases, it could.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34