hak*_*ata 1 c enums compiler-errors incomplete-type
我正在写一些代码,当我试图测试我的代码到现在为止,我得到一个错误.
这是我的代码:
#include <stdio.h>
enum { add = 0, addu, sub, subu } mips_opcode;
typedef enum mips_opcode mips_opcode_t;
typedef unsigned char byte; // 8-bit int
struct mips {
char *name;
byte opcode;
};
typedef struct mips mips_t;
void init (mips_t *out, char *name_tmp, mips_opcode_t opcode_tmp) {
out->name = name_tmp;
out->opcode = (byte)opcode_tmp;
}
int main (void) {
pritnf("no error i assume\n");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
并且命令行中的错误是:
main.c:14:55: error: parameter 3 ('opcode_tmp') has incomplete type
Run Code Online (Sandbox Code Playgroud)
我不能使用枚举作为参数或我在这里做错了什么?
它需要是这样的:
enum mips_opcode { add = 0, addu, sub, subu }; // type name is "enum mips_opcode"
typedef enum mips_opcode mips_opcode_t; // type alias
Run Code Online (Sandbox Code Playgroud)
甚至:
typedef enum { add = 0, addu, sub, subu } mips_opcode_t; // alias of anon. type
Run Code Online (Sandbox Code Playgroud)
不要混淆类型名称和变量!
(顺便说一句,Posix_t为类型保留了后缀,我相信......)
这条线是罪魁祸首:
enum { add = 0, addu, sub, subu } mips_opcode;
Run Code Online (Sandbox Code Playgroud)
您正在声明一个名为mips_opcode匿名enum类型的变量.
它应该是:
enum mips_opcode { add = 0, addu, sub, subu };
Run Code Online (Sandbox Code Playgroud)
枚举列表的名称紧跟在单词后面enum.
| 归档时间: |
|
| 查看次数: |
7888 次 |
| 最近记录: |