gpt4 book ai didi

c - 系统/stat.h :456: error: nested function 'stat' declared 'extern'

转载 作者:行者123 更新时间:2023-11-30 16:22:53 28 4
gpt4 key购买 nike

我有一个程序,是我通过修改原始暗网(深度学习图像识别,Yolov2)的许多地方而制作的。几个月前我一直在使用它,但是今天当我编译它时,它给了我一个错误:

gcc  -DSAVE_LAYER_INPUTS -DSAVE_INPUTS_LAYER_START=31 -DSAVE_INPUTS_LAYER_END=31 -DPRINT_INOUT -Wall -Wfatal-errors  -O3 -ffast-math -c ./src/convolutional_layer.c -o obj/convolutional_layer.o
In file included from ./src/convolutional_layer.c:463:
/usr/include/sys/stat.h: In function 'forward_convolutional_layer':
/usr/include/sys/stat.h:456: error: nested function 'stat' declared 'extern'

我使用 stat.h 来检查目录是否存在,如果不存在,则创建它。此错误出现在 #include 行和 stat.h 文件内。我查看了 stat.h,但不知道出了什么问题。 stat.h 看起来像这样(我显示了哪一个是第 456 行。)

#if defined __GNUC__ && __GNUC__ >= 2 && defined __USE_EXTERN_INLINES
/* Inlined versions of the real stat and mknod functions. */

__extern_inline int
__NTH (stat (__const char *__path, struct stat *__statbuf))
{ // <=== line 456
return __xstat (_STAT_VER, __path, __statbuf);
}

__NTH 只是添加一个关于 throw 的属性。问题是什么? (在 CentOS 6.9 上使用 gcc 4.4.7)

最佳答案

一般来说,系统 header 必须包含在代码中的任何函数之外。 C11 标准表示 §7.1.2 Standard headers (强调):

¶4 Standard headers may be included in any order; each may be included more than once in a given scope, with no effect different from being included only once, except that the effect of including <assert.h> depends on the definition of NDEBUG (see §7.2). If used, a header shall be included outside of any external declaration or definition, and it shall first be included before the first reference to any of the functions or objects it declares, or to any of the types or macros it defines. However, if an identifier is declared or defined in more than one header, the second and subsequent associated headers may be included after the initial reference to the identifier. The program shall not have any macros with names lexically identical to keywords currently defined prior to the inclusion of the header or when any macro defined in the header is expanded.

我在 POSIX 中没有找到等效的措辞,但您应该假设类似的规则适用。

鉴于提到“嵌套函数”的错误消息,您可能正在尝试包含 #include <sys/stat.h>从你的函数之一的范围内,并且考虑到 header 定义了一些内联函数,你不小心尝试将它们定义为嵌套函数,这通常是不允许的(尽管GCC对嵌套函数有一些支持,但你应该可能认为这是不可移植的)。

关于c - 系统/stat.h :456: error: nested function 'stat' declared 'extern' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54249730/

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