c++说:warning:语句对移位位操作符没有作用
g++ says: warning: statement has no effect for shift bits operators
我正在实现alkhwarizmi算法。
这是对的,但是我的g++编译器不喜欢移位操作符:>>和<<或者我做错了什么。
当我编译它时,我得到这样的输出:
> g++ -Wall -std=c++0x -o "Al-khwarizmi algorithm.o" "Al-khwarizmi algorithm.cpp" (in directory: /home/akronix/workspace/Algorithms)
> Al-khwarizmi algorithm.cpp: In function ‘int alkhwarizmi(int, int)’: Al-khwarizmi algorithm.cpp:31:9: warning: statement has no effect
> [-Wunused-value] Al-khwarizmi algorithm.cpp:34:9: warning: statement
> has no effect [-Wunused-value] Compilation finished successfully.
下面是我的代码:
int alkhwarizmi(int x, int y)
{
int sum = 0;
while (x>0)
{
if (x%2)
sum+=y;
//y *= 2;
y << 1;
cout << y <<endl;
//x /= 2;
x >> 1;
cout << x <<endl;
}
return sum;
}
如果我使用注释语句(简单的乘法和除法),一切正常
y << 1;
应该 y <<= 1; //^^equals y = y << 1;
下面的语句也是同样的问题:
x >>1; //^^same issue should be x >>= 1;
相关文章:
- 对字符串进行位操作
- 对字符数组中的元素执行逐位操作
- 逐位操作的隐式类型转换
- 如何进行特定的位操作?
- C++避免位操作完全移位
- 使用双包装器类进行位操作(C++、clang)修复性能下降问题
- 使用位操作优化检查
- 子集相关位操作
- 使用 c++ 提升库的按位操作
- 位操作和异或
- 位操作将最左侧的设置位转换为右侧交替位?
- 为什么对小于 4 个字节的整数类型的位操作会发生意外行为?
- POD 类型的原子按位操作
- 如何使用位操作在单个整数中编码和解码两个数字
- __int128的位操作
- 使用位操作会影响内存消耗?
- 在具有位操作的函数中获得值
- C/C 位操作不会导致预期输出
- 在数组大小中使用位操作的原因
- 了解C++位操作中的二进制转换实现