【问题标题】:Weird compiling behavior using enumeration as arguments使用枚举作为参数的奇怪编译行为
【发布时间】:2015-02-23 04:14:58
【问题描述】:

我正在尝试使用 XC8 编译器 v1.20 在 MPLAB-X 中编译这(部分)代码:

typedef enum i2cMode {MASTER = 0,SLAVE=1,OFF=2} i2c_mode;
void i2c_init(i2c_mode mode, uint8_t bus);

它位于头文件中。我尝试了每种组合,也没有数字关联,但最后它总是会输出:

(908) exit status = 1
make[2]: *** [build/pierin/production/main.p1] Error 1
../emu.X/i2c.h:48: error: label identifier expected
make[1]: *** [.build-conf] Error 2
../emu.X/i2c.h:48: error: "}" expected
make: *** [.build-impl] Error 2
../emu.X/i2c.h:48: error: no identifier in declaration
../emu.X/i2c.h:48: error: ";" expected
../emu.X/i2c.h:48: warning: missing basic type; int assumed
../emu.X/i2c.h:51: error: "," expected
../emu.X/i2c.h:51: error: can't mix prototyped and non-prototyped arguments
../emu.X/i2c.h:51: error: function body expected
main.c:41: error: undefined identifier "SLAVE"
main.c:41: error: too many function arguments

其中 48 是枚举类型定义,51 是函数原型。主要我可以看到这不会创建 SLAVE 枚举,也不会创建原型。 我需要使用普通变量吗?它应该可以工作,但事实并非如此。我想使用 i2c_mode 类型并使用枚举。这里是错误的还是不必要的?

【问题讨论】:

  • 请确认这个特定的编译器理解语法。我用 gcc 4.6.2 编译了你的代码,它工作得很好。
  • 它应该可以工作,但在 enum 关键字后面不带标签i2cMode 的情况下再试一次:typedef enum { MASTER=0, SLAVE=1, OFF=2 } i2c_mode;
  • 我已经做到了。所有组合。也没有为枚举变量分配数字。其余代码是正确的,因为没有枚举编译。

标签: c function parameters enums pic


【解决方案1】:

我解决了。这是自动读取正在读取默认 i2c.h 标头的链接外围库的问题,从而产生冲突。更改枚举名称已解决。谢谢。

【讨论】:

    猜你喜欢
    • 2012-11-15
    • 2017-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-03
    相关资源
    最近更新 更多