【发布时间】:2020-04-16 22:40:19
【问题描述】:
当我运行这个函数时,它给我一个setw(*torPtr - *harePtr) 和setw(*harePtr - *torPtr) 的警告
上面写着:
算术溢出:对 4 字节值使用运算符“-”,然后将结果转换为 8 字节值。在调用运算符“-”之前将值转换为更广泛的类型以避免溢出 (io.2)。
请问我该如何解决这个问题?
void Posi(const int* const tPtr,const int* const hPtr)
{
if (*hPtr == *tPtr) {
cout <<setw(*hPtr) << "bang!" << '\a';
}
else if (*hPtr < *tPtr) {
cout << setw(*hPtr) << 'H' << setw(*tPtr - *hPtr) << 'A';
}
else {
cout << setw(*tPtr) << 'T' << setw(*hPtr - *tPtr) << 'B';
}
}
【问题讨论】:
-
我无法重现,一切正常wandbox.org/permlink/jfz1q5uZoUKoDcdS,问题一定是其他问题,发帖minimal reproducible example
-
哇,当没有演员表时,错误消息抱怨“演员表”?这里的术语应该是“转换”。编译器编写者应该知道其中的区别。