小编Tho*_*s M的帖子

C头文件中的枚举在多个文件中共享

我想定义一个枚举类型ONCE,并在包含该文件时在所有其他文件中共享该类型,但是我不断收到以下错误:

$ gcc -std=c99 main.c invoc.h invoc.c
main.c: In function ‘main’:
main.c:12: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘pr_alg’
main.c:12: error: ‘pr_alg’ undeclared (first use in this function)
main.c:12: error: (Each undeclared identifier is reported only once
main.c:12: error: for each function it appears in.)
main.c:13: error: ‘FIFO’ undeclared (first use in this function)
invoc.c:7: error: expected ‘)’ before ‘myalg’
Run Code Online (Sandbox Code Playgroud)

代码如下:

invoc.h:

#define INVOC_H
#ifndef INVOC_H

typedef enum {FIFO, SECOND_CHANCE, RANDOM, NRU, CLOCK, AGING} alg_t;

void …
Run Code Online (Sandbox Code Playgroud)

c enums header-files

2
推荐指数
1
解决办法
161
查看次数

标签 统计

c ×1

enums ×1

header-files ×1