C在头文件中创建volatile sig_atomic_t全局

时间:2012-11-20 01:13:28

标签: c global volatile sigint sig-atomic-t

我正在尝试创建一个全局变量,在我的msh.c文件中初始化为:

volatile sig_atomic_t sig_int = 0;

这一点似乎没问题。但是,如果我转到我的proto.h文件(包含在此项目的所有c文件中),并键入:

extern volatile sig_atomic_t sig_int;

它引发了一堆错误:

gcc -c -Wall msh.c arg_parse.c builtin.c expand.c
In file included from arg_parse.c:5:
proto.h:3: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘sig_int’
In file included from builtin.c:13:
proto.h:3: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘sig_int’
In file included from expand.c:11:
proto.h:3: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘sig_int’
make: *** [msh.o] Error 1

我究竟如何将此变量设为全局变量?感谢。

1 个答案:

答案 0 :(得分:1)

您的proto.h文件需要包含<signal.h>,以便定义sig_atomic_t类型,这就是全部。

相关问题