This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: signed/unsigned right shift


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]