Why >>24 causes -Wconversion but >>23 doesn't?

早过忘川 提交于 2019-11-29 13:38:37

As mentioned by Shafik Yaghmour, this appears to be a bug in GCC:

GCC Bug 40752: -Wconversion generates false warnings for operands not larger than target type

It appears to have been present since version 4.4.0, first reported on 2009-07-14, and has 5 duplicates. Based on the comments in the bug report, there seems to be some debate on how to handle it.

At least with gcc 5.4, 6.x and 7.x this issue has a simple work-around using a cast:

#include <stdint.h>

unsigned char f(uint32_t RGBA)
{
  return (unsigned char) ((RGBA>>24) & 0xFF);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!