signed/unsigned right shift

Ian Lance Taylor ian@wasabisystems.com
Mon Mar 15 22:17:00 GMT 2004


Christian Groessler <cpg@aladdin.de> writes:

> Sentence 2 says "If an int can represent all values of the original
> type, the value is converted to an int; otherwise, it is converted to
> an unsigned int."
> 
> Seems to suggest that the conversion "unsigned short" to "signed int"
> is ok.
> 
> But sentence 3 says "The integer promotions preserve value including
> sign."
> 
> So shouldn't the conversion be "unsigned short" to "unsigned int"?

Sentence 3 means that both the value and the sign of the value (i.e.,
positive or negative) are preserved.

Your suggestion would be expressed as "The integer promotions preserve
value including signedness."

K&R C was signedness preserving.  ISO C is value preserving.  A quick
Google search turned up this page on the topic:
    http://ou800doc.caldera.com/SDK_cprog/_Background.html

Ian



More information about the Gcc mailing list