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


On 03/14/2004 01:23:18 PM EST Ian Lance Taylor wrote:
>
>Christian Groessler <cpg@aladdin.de> writes:
>
>> >Correct, the multiplication is done as signed int.  And it is
>> >implementation
>> >defined whether right shift of a negative signed int does sign fill or
>> >not.
>> >So both compilers are right; it is only your code that's wrong.
>> >
>> >C89 references: 3.3.7, 3.2.1.5, 3.2.1.1.
>>
>> Hmm, unfortunately I don't have the c89 standard document. Can
>> somebody point me to the equvalent sections in c99?
>

>Integer promotions: 6.3.1.1.

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"?

regards,
chris


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