【问题标题】:What warning to enable that implicit conversion from typedef (uint32_t) to uint32_t results in warning, clang启用从 typedef (uint32_t) 到 uint32_t 的隐式转换的警告会导致警告,clang
【发布时间】:2021-08-14 17:42:53
【问题描述】:

我希望给定的示例会导致编译器警告,因为存在从 error_t 到 int 的隐式转换。

我正在使用带有 C 而非 C++ 的 ARM 的 segger clang 编译器。

typedef uint32_t error_t ; 

error_t Test(error_t test){
  return test;
}

int main(){
  error_t e = 0;
  uint32_t t32 = Test(e);
}

【问题讨论】:

    标签: c clang warnings typedef


    【解决方案1】:

    typedef 只是类型的别名,因此error_tuint32_t 相同。因此,转换不会发出警告。

    只有在可能丢失精度的情况下才会出现算术类型之间的类型转换警告,并且只有在启用了-Wall-Wextra 中未包含的某些选项时才会出现。

    【讨论】:

      猜你喜欢
      • 2011-07-23
      • 2017-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-04
      • 1970-01-01
      • 2017-03-05
      • 1970-01-01
      相关资源
      最近更新 更多