Where is ptrdiff_t
defined in C? If non-trivial, how can I make this type visible from GCC on Linux?
views:
80answers:
2
+11
A:
It's defined in stddef.h
.
That header defines the integral types size_t
, ptrdiff_t
, and wchar_t
, the functional macro offsetof
, and the constant macro NULL
.
GMan
2010-08-30 03:50:59
Bizarrely, it's located at `linux/stddef.h` (but includes fine with `#include <stddef.h>`. It only contains definition for `NULL` (but including it gives me `ptrdiff_t`). There's some header trickery going on here which prevented me from grepping it in the first place. Can you enlighten?
Matt Joiner
2010-08-30 04:02:07
And, of those, only `ptrdiff_t` and `offsetof` are not defined in any other place; the other three are defined by a number of other headers too.
Jonathan Leffler
2010-08-30 04:04:24
@Matt: There's no definition of `ptrdiff_t` at all? Strictly speaking, a compiler doesn't have to implement anything in the header. It could get by by simply noting that if `stddef.h` is included, it will internally define `ptrdiff_t` and so on. That could be it, I don't have your version of the header available to look, though.
GMan
2010-08-30 04:06:44
@Matt: the headers on Linux are an intricate construction that have to meet a large number of competing standards and requirements. The detailed implementation of the C standard headers is entirely up to the implementation; they need not be files, even (though they most commonly are files). To find something, use (for instance): `grep -R ptrdiff_t /usr/include`.
Jonathan Leffler
2010-08-30 04:07:54
The real `stddef.h` is hiding under `/usr/lib/gcc/TARGET/VERSION/include` along with a number of other headers that belong to GCC (and may be GCC-version specific) rather than the C libraries. `linux/stddef.h` is only used for kernel code (and I don't honestly see why they bother having their own copy). You may find the `-H` switch to gcc useful for investigating this kind of question.
Zack
2010-08-30 04:08:45
@Zack: Your comment could be an answer by itself. Thanks for clearing this up.
Matt Joiner
2010-08-30 08:40:35