Re: Type conversion
- From: richard@xxxxxxxxxxxxxxx (Richard Tobin)
- Date: 31 Jan 2008 13:21:44 GMT
In article <m3y7a6cfzp.fsf@xxxxxxxxxxxxxxx>,
Mark L Pappin <mlp@xxxxxxx> wrote:
int a = 0x12345678;
char b;
b=(char)a;
Would the value of b depend on the endianness of the machine?
Yes.
Casts, like most other operations, are defined in terms of value, not
representation, no? Thus the low-order 8 bits will be used, and in
this instance since
(a & 0xff) == (a & 0x7f)
even the signedness of 'char' is irrelevant as values up to 127 are
guaranteed representable even in 'signed char'.
If char is signed, we have a conversion to a signed integer with
smaller size, and in that case if the value cannot be represented
the result is implementation-defined.
-- Richard
--
:wq
.
- References:
- Type conversion
- From: manik
- Re: Type conversion
- From: santosh
- Type conversion
- Prev by Date: Re: Question on accessing structure
- Next by Date: Re: declaration of variable in for loop
- Previous by thread: Re: Type conversion
- Next by thread: Re: Type conversion
- Index(es):
Relevant Pages
|