I'm just wondering why things like uintptr_t
are in stdint.h
, but other types like size_t
are in stddef.h
? Is there logic behind these headers?

- 78,363
- 46
- 261
- 468
-
2`stdint` is newer and moving them would break existing code? – Retired Ninja Jun 17 '18 at 02:01
-
Didn't know that. So it's a legacy thing. Wonder who thought the it was worth including another file for newer int types? `stddef` actually sounds like a better more generic include file. – Evan Carroll Jun 17 '18 at 02:02
-
2Because `stddef.h` is really tiny. It has barely anything in it and the intention is to let you include types and macros that may as well have been part of the core language, and without worrying too much about including it from a header even. `stdint.h` is potentially a much larger file and many of the types aren't even guaranteed to exist. – Veltas Jun 17 '18 at 02:19
-
2`ssize_t` is not defined by C. It's defined by POSIX, which declares it in `
` and ` – Keith Thompson Jun 17 '18 at 02:46`. I think your question would make more sense if you referred to `size_t` rather than `ssize_t`. -
@KeithThompson ekk that was a typo – Evan Carroll Jun 17 '18 at 02:47
-
There is more information about `stdint.h` in the [C99 rationale](http://www.open-std.org/jtc1/sc22/wg14/www/C99RationaleV5.10.pdf), which explains that the header was introduced as a lighter version of `inttypes.h` which was based on a header with the same name conventionally provided by C compilers at the time. – Veltas Jun 17 '18 at 03:11
1 Answers
The reasoning is largely a matter of convention and history.
<stddef.h>
and size_t
have been around since at least the 1989 ANSI standard of C (the 1978 book The C Programming Language does not mention the header or size_t
, and sizeof
expressions had type int
- this made sense in ecosystems where the 'natural word size' of the processor was also the size of addresses and indices on the system).
<inttypes.h>
and <stdint.h>
were added to standard C for the 1999 revision, and their presence is explained in the C99 Rationale.
<inttypes.h>
was derived from the header of the same name found on several existing 64-bit systems. The Committee debated other methods for specifying integer sizes and other characteristics, but in the end decided to standardize existing practice rather than innovate in this area. ...<stdint.h>
is a subset of<inttypes.h>
more suitable for use in freestanding environments, which might not support the formatted I/O functions. In hosted environments, if the formatted conversion target is not wanted, using this header instead of<inttypes.h>
avoids defining such a larger number of macros.

- 1,003
- 6
- 19
-
I can't find a source for this but I have a hunch `size_t` first appeared in `
`, which is a UNIX header mentioned in the 1978 TCPL, and ironically is the header containing your typo'd `ssize_t`. – Veltas Jun 17 '18 at 04:01 -
2As far as standard headers go, `
` was a C standards committee invention in C89/C90 to contain some items that had no better place to go — and that included `size_t`, `ptrdiff_t`, `offsetof`, `NULL`. As you said, ` – Jonathan Leffler Jun 17 '18 at 06:18` was added in C99. While `size_t` could also have been added to that header, there wasn't really a need to do so. That header covered different styles of integer type than `size_t`.