This header file shall define NULL
or size_t
and other macros, but I find that /usr/include/linux/stddef.h
is empty? Why?
-
http://clang.llvm.org/doxygen/stddef_8h_source.html – moffeltje Jul 08 '15 at 06:49
-
2Nominally, you include `/usr/include/stddef.h` when you write `#include
`. What that does is up to the implementation. Maybe there's nothing needed in the `linux/stddef.h` header — the standard one, or a header included from another sub-directory, contains all that's necessary. – Jonathan Leffler Jul 08 '15 at 07:49
1 Answers
The actual location of the headers is implementation defined. What you look at is not the typical <stddef.h>
included by gcc. You can find out exactly where it's located on your system with:
gcc -E - <<<'#include<stddef.h>' | grep stddef.h
which is equivalent to including the header <stddef.h>
in an empty C file and running gcc -E
on it.
The headers in /usr/include/linux
are used to compile the C library (usually glibc on Linux). The GNU manual says:
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’.
whereas the C library headers are usually placed by somewhere in /usr/lib/
. On my ubuntu 15.04, the header /usr/include/linux/stddef.h
is empty. But on my CentOS, it has:
#ifndef _LINUX_STDDEF_H
#define _LINUX_STDDEF_H
#undef NULL
#if defined(__cplusplus)
#define NULL 0
#else
#define NULL ((void *)0)
#endif
#endif
The bottom line is, this is NOT the stddef.h
you are interested in and in general, you should not make any assumptions about the location of the standard header files.

- 117,907
- 20
- 175
- 238
-
does `- <<<` is a specific syntax for `gcc`, that is, it is not valid in shell – zhy Jul 29 '16 at 12:59
-
1@zhy `-` is something gcc understands. It means "read input from standard input". OTOH, `<<<` is bash specific (which is the default shell on most Linux distros), called as "here strings". If `<<<` isn't available then you can write the same as: `echo '#include
' | gcc -E - | grep stddef.h`. – P.P Jul 29 '16 at 13:24 -
I understand now. `<<<` means a here string, `<<` is a here document. Thank you! – zhy Jul 30 '16 at 02:42