gpt4 book ai didi

c - 为什么/usr/include/linux/stddef.h 是空的?

转载 作者:IT王子 更新时间:2023-10-29 00:06:18 30 4
gpt4 key购买 nike

这个头文件应该定义NULLsize_t等宏,但是我发现/usr/include/linux/stddef.h是空的?为什么?

最佳答案

header 的实际位置是实现定义的。你看的不是典型的<stddef.h>包含在 gcc 中。您可以通过以下方式准确找到它在系统中的位置:

gcc -E - <<<'#include<stddef.h>' | grep stddef.h

相当于包含标题 <stddef.h>在一个空的 C 文件中运行 gcc -E在上面。

/usr/include/linux 中的 header 用于编译 C 库(通常是 Linux 上的 glibc)。 GNU manual说:

The linux, asm and asm-generic directories are required to compile programs using the GNU C Library; the other directories describe interfaces to the kernel but are not required if not compiling programs using those interfaces. You do not need to copy kernel headers if you did not specify an alternate kernel header source using ‘--with-headers’.

而 C 库头文件通常放在 /usr/lib/ 中的某处.在我的 ubuntu 15.04 上, header /usr/include/linux/stddef.h是空的。但是在我的 CentOS 上,它有:

#ifndef _LINUX_STDDEF_H
#define _LINUX_STDDEF_H

#undef NULL
#if defined(__cplusplus)
#define NULL 0
#else
#define NULL ((void *)0)
#endif

#endif

底线是,这不是 stddef.h您对标准头文件的位置感兴趣,并且一般来说,您不应该对标准头文件的位置做出任何假设。

关于c - 为什么/usr/include/linux/stddef.h 是空的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31285258/

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