Is something wrong with the compiler ?

csp csp at gtenmc.UUCP
Wed Sep 26 03:01:15 AEST 1990


   Assuming that the 2's complement system is used to represent the negative
   integers. I wrote the following code , and the results I got were absurd.

C code :

   main()
   {
      int a;
      printf(" Maxint : %d\na = %d\n", ( int )(( unsigned ) ~0 >> 1 ) , 
	      a = ( int )(( unsigned ) ( a = ~0 ) >> 1 ));
   }

 Output :

    Maxint : -1 
    a = 2147483647 

Can some complier writer tell me why this is happening ?

csp - csp at gtenmc.UUCP

K&R C > ANSI C



More information about the Comp.lang.c mailing list