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 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.


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