Re: Type conversion
- From: Eric Sosman <esosman@xxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 31 Jan 2008 09:29:35 -0500
santosh wrote:
manik wrote:
Assuming int is 32 bits and char is 8 bits on my machine
Say I have the following piece of code
int a = 0x12345678;
char b;
b=(char)a;
What would be the value of b?
Would the value of b depend on the endianness of the machine?
Yes.
No; endianness doesn't affect the outcome.
Also note that for maximum portability use either signed or
unsigned char for holding non-character values. The signedness of plain
char is implementation dependant, thus creating needless
non-portability.
Right. If char is unsigned (and eight bits wide, by
assumption), the value stored in `b' will be 0x78 == 120.
If char is signed, the conversion to char produces an
implementation-defined result or raises an implementation-
defined signal ("trap").
--
Eric Sosman
esosman@xxxxxxxxxxxxxxxxxxxx
.
- References:
- Type conversion
- From: manik
- Re: Type conversion
- From: santosh
- Type conversion
- Prev by Date: Re: #define
- Next by Date: Re: #define
- Previous by thread: Re: Type conversion
- Next by thread: Re: Type conversion
- Index(es):
Relevant Pages
|