This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: signed/unsigned right shift
- From: Ian Lance Taylor <ian at wasabisystems dot com>
- To: Christian Groessler <cpg at aladdin dot de>
- Cc: GCC List <gcc at gcc dot gnu dot org>
- Date: 15 Mar 2004 17:16:55 -0500
- Subject: Re: signed/unsigned right shift
- References: <87ish53h24.fsf@aladdin.de>
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