Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C库的内部头约定_C_Header_Internal_Convention_Project Structure - Fatal编程技术网

C库的内部头约定

C库的内部头约定,c,header,internal,convention,project-structure,C,Header,Internal,Convention,Project Structure,是否有将公共接口头和内部头分开的约定?我查看了一些库,发现大多数内部头位于名为somethinternal.h的src目录中,公共头位于include目录中。我在想这样的事情: (xyz是库名称) 包含/xyz/something.h(公共界面) src/something.h(内部标题) src/something.c /* not xyz/something.h, but the private header in src/ */ #include "something.h" void d

是否有将公共接口头和内部头分开的约定?我查看了一些库,发现大多数内部头位于名为
somethinternal.h
src
目录中,公共头位于
include
目录中。我在想这样的事情:

xyz
是库名称)

包含/xyz/something.h
(公共界面)

src/something.h
(内部标题)

src/something.c

/* not xyz/something.h, but the private header in src/ */
#include "something.h"

void do_something(struct something *s) {
        /* function definition */
}
所以请注意,我没有使用
-internal
后缀,因为在我看来,如果标题位于
src
目录中,那么它是内部的。例如,对于新的贡献者来说,这是否足够清楚?还是应该添加
-内部
后缀以清晰起见


`我认为你的建议很好。linux内核使用类似的布局,在include/下使用public
sched.h
,在kernel/sched下使用private
sched.h
——Frederik Deweerdt

可以使用相同的名称命名两个不同的东西confusing@PeterMiehle即使附加了像
xyz/something.h
这样的目录,我认为你的建议是完美的好的linux内核使用类似的布局,包括/下的public
sched.h
,以及kernel/schedAlright下的private
sched.h
!然后我将使用我的布局。谢谢如果文件名相同,如何处理include-guard宏?它们通常与文件名同名。私有实现代码可能需要同时包含public和private头。@Sam,您可以对每个文件使用一次
#pragma
或使用不同的宏。
/* include public header */
#include "xyz/something.h"

/* struct definition in internal header for opaque struct */
struct something { int x, int y };
/* not xyz/something.h, but the private header in src/ */
#include "something.h"

void do_something(struct something *s) {
        /* function definition */
}