Re: casting
- From: CBFalconer <cbfalconer@xxxxxxxxx>
- Date: Fri, 09 Jun 2006 05:33:57 -0400
Christian Christmann wrote:
.... snip ...
a question on castings.
My code example:
#include <stdio.h>
int main( void )
{
unsigned int a = 4294967295U;
signed int b = 4294967295U;
signed int c = (signed int) a;
printf( "a:%ud\n", a );
printf( "b:%ud\n", b );
printf( "c:%ud\n", c );
return 0;
}
The output is:
a:4294967295d
b:4294967295d
c:4294967295d
I don't understand why "b" and "c" are also a 32-bit values.
Trying to stuff a value into a signed object that cannot hold that
value results in implementation defined behaviour. You could have
just set off that 3 tons of fertilizer they found in Canada. Only
stuffing into unsigned objects has a defined action.
--
"Our enemies are innovative and resourceful, and so are we.
They never stop thinking about new ways to harm our country
and our people, and neither do we." -- G. W. Bush.
"The people can always be brought to the bidding of the
leaders. All you have to do is tell them they are being
attacked and denounce the pacifists for lack of patriotism
and exposing the country to danger. It works the same way
in any country." --Hermann Goering.
.
- Follow-Ups:
- Re: casting
- From: Keith Thompson
- Re: casting
- References:
- casting
- From: Christian Christmann
- casting
- Prev by Date: Re: Structure of functions
- Next by Date: Re: Why the C committee doesn't provide an implementation when the standard is published?
- Previous by thread: Re: casting
- Next by thread: Re: casting
- Index(es):
Relevant Pages
|