Bug? Bitwise ops on shorts upconvert to ints and warning

Bug? Bitwise ops on shorts upconvert to ints and warning

Say I use this code to swap little with big endian, where *rp is a unsigned short *:

*rp = (*rp & 0xff00u) >> 8 | (*rp & 0x00ffu) << 8;

Result:

remark #810: conversion from "unsigned int" to "unsigned short" may lose significant bits

(with arrow pointing to the assignment)

At first I thought it saw the literal as an int, but then I replaced the expression by *rp & *rp and got the same error.

So, what gives? I didn't find any mention on the Web that bitwise ops upconverted to ints or unsigned ints.

1 条帖子 / 0 全新
如需更全面地了解编译器优化,请参阅优化注意事项