【问题标题】:static_cast<unsigned> vs static_cast<unsigned int> [duplicate]static_cast<unsigned> vs static_cast<unsigned int> [重复]
【发布时间】:2020-09-13 18:43:01
【问题描述】:

我是 C++ 新手,所以请轻描淡写。 我正在使用 resharper 将一些代码从 c 风格强制转换为 c++ 风格强制转换。

这里的代码:

(unsigned int)(ch - start) <= (unsigned int)(end - start);

改为

static_cast<unsigned>(ch - start) <= static_cast<unsigned>(end - start);

代替:

static_cast<unsigned int>(ch - start) <= static_cast<unsigned int>(end - start);

有什么不同吗?而且,有没有性能差异?这被称为 十亿 次。

【问题讨论】:

  • 没有任何区别。两者的意思是一样的。按照惯例,int 部分经常被省略。
  • @Ron 性能怎么样?
  • unsigned intunsigned 本身的含义相同。在 unsigned 本身的情况下,int 是隐含的。没有性能差异。
  • 啊,好的。明白了,谢谢!

标签: c++ casting resharper


【解决方案1】:

有什么不同吗?

unsigned intunsigned 多 4 个字符。没有其他区别。

还有,性能有什么区别吗?

没有。

【讨论】:

    猜你喜欢
    • 2020-04-08
    • 1970-01-01
    • 2016-07-29
    • 1970-01-01
    • 2011-04-08
    • 1970-01-01
    • 1970-01-01
    • 2021-12-30
    • 1970-01-01
    相关资源
    最近更新 更多