[英]Why you should use unsigned int instead of just unsigned?
I have a colleague that is not keen on using modern C++ 我有一个不热衷于使用现代C ++的同事
For example when I asked him to start using r_value reference he wouldn't do it. 例如,当我要求他开始使用r_value引用时,他不会这样做。 When I asked him to use std::array instead of c arrays (char example[8]) he wouldn't do it. 当我要求他使用std :: array而不是c数组(char example [8])时,他不会这样做。 When I asked him to stop doing c casts ( A* a = (A*)b ) he wouldn't do it. 当我要求他停止进行c转换(A * a =(A *)b)时,他不会这样做。 You get my point. 你明白我的意思。
Usually I can find references of Scott Meyers or Bjarne Stroustrup of why modern C++ shouldn't be used this way, and then he cannot debate it anymore. 通常,我可以找到Scott Meyers或Bjarne Stroustrup的参考文献,以解释为什么不应该以这种方式使用现代C ++,然后他再也无法对此进行辩论。
Unfortunately I cannot find a direct reference of anyone why is bad practise to use "unsigned" instead of "unsigned int". 不幸的是,我找不到任何人的直接参考,这是为什么使用“无符号”而不是“无符号int”的错误做法。 I managed to make me him used "singed" before "int but I cannot convince him to use "unsigned int". 我设法让他在“ int”之前使用“ singed”,但是我不能说服他使用“ unsigned int”。
So my question is should we use "unsigned int" instead of "unsigned"? 所以我的问题是我们应该使用“ unsigned int”而不是“ unsigned”吗?
I cannot find a direct reference of anyone why is bad practise to use "unsigned" instead of "unsigned int" 我找不到任何人的直接参考,为什么不好的做法是使用“ unsigned”而不是“ unsigned int”
That's probably because it isn't a practice that's considered bad by the majority (to my knowledge). 据我所知,这可能是因为多数人认为这不是一种不好的做法。
unsigned
and unsigned int
are exactly the same type, just as signed
, signed int
and int
are. unsigned
和unsigned int
是完全相同的类型,就像signed
, signed int
和int
一样。 I don't know of a case where using one over the other would have surprising results. 我不知道在一个案例中使用一个案例会产生令人惊讶的结果。
Given that the choice is primarily a matter of taste. 鉴于选择主要取决于口味。 Arguing about the choice is bike-shedding. 争论的选择是骑自行车。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.