c - Double to enum cast 警告类型混合

标签 c casting enums compiler-warnings

我有以下 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 编译器

最佳答案

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

类似于:

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

关于c - Double to enum cast 警告类型混合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17083596/

相关文章:

C程序-动态规划算法中奇怪的段错误

c - C语言广播

c - C 中的 sprintf 和 unsigned int 数组

java - 获取数字的字符代码

delphi - 如何将指针转换为泛型参数类型?

c# - 在 C# 中将字符串转换为枚举

c - 链表 createList 与 initNode 函数

java - 从公共(public)抽象类扩展而来的 Java 类之间的转换

java - 无法将数据库条目映射到 java 枚举

swift - 具有 String 表示形式的 Int 枚举