This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/46090] New: 16 bit uint16_t puts non-zero in highest bits when shifting
- From: "kshakhna at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 20 Oct 2010 03:47:26 +0000
- Subject: [Bug c/46090] New: 16 bit uint16_t puts non-zero in highest bits when shifting
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46090
Summary: 16 bit uint16_t puts non-zero in highest bits when
shifting
Product: gcc
Version: 4.6.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: kshakhna@gmail.com
This problem occurred on 64-bit Linux platform.
Here is an example of code for reproducing problem.
#include <stdint.h>
uint16_t In16(uint16_t input)
{
uint16_t len = (input * 0x0101) >> 8;
return len;
}
int len = In16(0x808);
When passing input=0x808, expected result:
1. len = (input * 0x0101) >> 8;
2. len = (0x808 * 0x0101) >> 8;
3. len = (0x808 + 0x0800) >> 8;
4. len = 0x1008 >> 8;
5. len = 0x10;
Instead of 0x10, result is 0x810
3. len = (0x808 + 0x80800) >> 8;
Here higher than 16 bit is not truncated.
4. len = 0x81008 >> 8;
5. len = 0x810;