Re: casting



Christian Christmann wrote:

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.
.... snip ...

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.

.



Relevant Pages

  • Re: C standard question?
    ... uc1 gets promoted to a signed int ... On many implementations, perhaps including all those you have ever ... uc1 gets promoted to signed int. ... Of course, on implementations where uc1 is promoted to unsigned int, ...
    (comp.lang.c)
  • Re: GCC bitfield packing
    ... The actual amount of storage taken us depends only upon the number of ... depend upon the type of the bitfield declaration. ... _Bool, int, signed int, and unsigned int. ...
    (comp.std.c)
  • Re: Promotion and assignment
    ... Tomás Ó hÉilidhe wrote: ... signed int or unsigned int ... that the lvalue E1 is evaluated only once." ...
    (comp.lang.c)
  • Re: Typedef Bug/Error
    ... Integer types ... presence of the initial u are defined, ... uint32_t exists as unsigned int and has a corresponding ... type under 6.2.5, namely signed int. ...
    (comp.lang.c)
  • Re: Translating a bitwise operation from C++
    ... Dim result as ULong ... Everything should be uinteger I believe. ... will default to signed int. ... To avoid errors you need to define everything as unsigned int. ...
    (microsoft.public.dotnet.languages.vb)