gpt4 book ai didi

C 在头文件中使 volatile sig_atomic_t 全局化

转载 作者:太空宇宙 更新时间:2023-11-04 03:59:22 24 4
gpt4 key购买 nike

我正在尝试创建一个全局变量,在我的 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

我该如何使这个变量成为全局变量?谢谢。

最佳答案

你的 proto.h文件需要包含 <signal.h>这样 sig_atomic_t定义了类型,仅此而已。

关于C 在头文件中使 volatile sig_atomic_t 全局化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13465179/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com