有人知道为什么uint8_t&uint8_t会产生int吗?
#include <iostream>
#include <type_traits>
#include <cstdint>
#include <typeinfo>
using namespace std;
int main() {
{
uint8_t a {}, b{};
auto c = a & b ;
cout << is_unsigned<decltype(a)>::value << " "<< is_unsigned<decltype(b)>::value
<< " "<< is_unsigned<decltype(c)>::value << " "<< is_unsigned<decltype( a & b)>::value << " ";
cout << "\t " << typeid(a).name() << " " << typeid(c).name() << endl;
}
cout << endl;
{
uint32_t a {}, b{};
auto c = a & b ;
cout << is_unsigned<decltype(a)>::value << " "<< is_unsigned<decltype(b)>::value
<< " "<< is_unsigned<decltype(c)>::value << " "<< is_unsigned<decltype( a & b)>::value << " ";
cout << "\t " << typeid(a).name() << " " << typeid(c).name() << endl;
}
cout << endl;
{
size_t a {}, b{};
auto c = a & b ;
cout << is_unsigned<decltype(a)>::value << " "<< is_unsigned<decltype(b)>::value
<< " "<< is_unsigned<decltype(c)>::value << " "<< is_unsigned<decltype( a & b)>::value << " ";
cout << "\t " << typeid(a).name() << " " << typeid(c).name() << endl;
}
}住在这里:胡桃
产出如下:
1 1 0 0 h i
1 1 1 1 j j
1 1 1 1 m m我没有找到任何线索,只是:
运算符的结果&是操作数的位和值(在通常的算术转换之后)。
所以,我不知道它是标准的还是实现的依赖者。
(谢谢你的帮助:)
发布于 2017-12-06 17:24:37
请参见推广所有算术操作都会将小于int的整数类型推广到int或无符号int。
https://stackoverflow.com/questions/47679982
复制相似问题