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/12/2004 02:34:46 PM PST Dale Johannesen wrote:
>
>On Mar 12, 2004, at 2:24 PM, Andreas Schwab wrote:
>> Christian Groessler <cpg@aladdin.de> writes:
>>> I have the following program which takes 2 unsigned short values,
>>> multiplies them and shifts the result right.
>>>
>>> This right shift gives a value with 1s bits at the high end.
>>
>> This is correct.  The promotion rules let unsigned short promote to
>> int,
>> since the latter can represent all values of the former.
>
>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?

regards,
chris


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