Summary: | bit shift + compare returns wrong value | ||
---|---|---|---|
Product: | gcc | Reporter: | layer |
Component: | c | Assignee: | Not yet assigned to anyone <unassigned> |
Status: | RESOLVED INVALID | ||
Severity: | normal | ||
Priority: | P3 | ||
Version: | 6.3.1 | ||
Target Milestone: | --- | ||
Host: | Target: | ||
Build: | Known to work: | ||
Known to fail: | Last reconfirmed: |
Description
layer
2017-01-18 23:58:58 UTC
And the code: #include <stdio.h> /* whatever the shift in badexample does, * the function should never return 1 */ long badexample(unsigned long iv) { long ov = ((long)(1)) << ((iv & 0x3f) + 1); if (ov == 1) ov = 0; return ov; } int main() { int i; for(i=60;i<65;i++) printf("%d=>0x%lx\n",i&63,badexample(i&63)); } 1ull << 64 is undefined in C and C++ standards. But results are correct. |