【问题标题】:Double to enum cast warns types mixedDouble to enum cast 警告类型混合
【发布时间】:2013-06-13 09:26:33
【问题描述】:

我有以下 C 代码行,其中 cfType 是普通的 C 枚举类型:

int foo (double * parameters) {
...
cfType coefSelect = (cfType) *parameters; /* The double pointed by at parameters
                                           * is cast to a cfType enum and result
                                           * is put in the var coefSelect.
                                           */
...
}

但是编译器在强制转换行给出“枚举类型与另一种类型混合”的警告 - 但强制转换不应该阻止这个警告吗?

我在 Code Composer Studio 中使用 Texas Instruments 的 C2000 C 编译器

【问题讨论】:

  • enums 是 int 类型
  • @GrijeshChauhan 他们不是,enum 是整数类型
  • 奇怪的设计... S-/

标签: c casting enums compiler-warnings


【解决方案1】:

我认为您必须先转换为整数类型才能防止出现此警告。

类似:

cfType coefSelect = (cfType)(int) *parameters;

【讨论】:

    【解决方案2】:

    尝试分两步进行投射:

    cfType coefSelect = (cfType) (int) *parameters; 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-24
      • 1970-01-01
      • 1970-01-01
      • 2012-03-07
      相关资源
      最近更新 更多