相关疑难解决方法(0)

Bitshift和整数推广?

通常,C要求将二元运算符的操作数提升为更高级别操作数的类型.这可以被利用来避免用详细的强制转换填充代码,例如:

if (x-48U<10) ...
y = x+0ULL << 40;
Run Code Online (Sandbox Code Playgroud)

等等

但是,我发现,至少对于gcc,这种行为不适用于位移.即

int x = 1;
unsigned long long y = x << 32ULL;
Run Code Online (Sandbox Code Playgroud)

我希望右手操作数的类型可以促使左手操作数被提升,unsigned long long以便移位成功.但相反,gcc会打印一个警告:

warning: left shift count >= width of type
Run Code Online (Sandbox Code Playgroud)

gcc是否被破坏,或标准是否对位移的类型提升规则有所例外?

c standards gcc bit-manipulation integer-promotion

28
推荐指数
1
解决办法
5272
查看次数

标签 统计

bit-manipulation ×1

c ×1

gcc ×1

integer-promotion ×1

standards ×1