简体   繁体   English

为什么您应该使用unsigned int而不是unsigned?

[英]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. unsignedunsigned int是完全相同的类型,就像signedsigned intint一样。 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.

相关问题 为什么“ unsigned int” +“ unsigned int”返回“ unsigned int”? - Why does “unsigned int” + “unsigned int” return an “unsigned int”? 在这种情况下,为什么要使用“无符号”整数? : - Why should I use 'unsigned' integer in this case? : 使用 STL 容器时应该使用 int 还是 unsigned int? - Should I use int or unsigned int when working with STL container? 为什么声明“score[11] = {};” 和“等级”为“无符号”而不是“int” - why declare “score[11] = {};” and “grade” as “unsigned” instead of "int' OpenGL选择缓冲区-使用指向对象的指针而不是无符号的Int? - OpenGL Selection Buffer - Use A Pointer to the Object Instead of an Unsigned Int? 为什么 (-i) 的类型,其中 i 是 unsigned int,仍然是 unsigned int? - Why is the type of (-i), where i is unsigned int, still unsigned int? 省略数据类型(例如“ unsigned”而不是“ unsigned int”) - Omitting the datatype (e.g. “unsigned” instead of “unsigned int”) 为什么或为什么不使用'UL'来指定unsigned long? - Why or why not should I use 'UL' to specify unsigned long? 将unsigned int *'转换为'unsigned int *& - convert unsigned int *' to 'unsigned int *& 为什么C ++流使用char而不是unsigned char? - Why do C++ streams use char instead of unsigned char?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM