OS: Debian 9 (Linux 4.9)
Compiler: GCC 8.2
Currently I am including <stddef.h>
(where size_t
is defined) and <stdint.h>
(where most integral types are defined), but I still don't have ssize_t
.
Where is it defined?
OS: Debian 9 (Linux 4.9)
Compiler: GCC 8.2
Currently I am including <stddef.h>
(where size_t
is defined) and <stdint.h>
(where most integral types are defined), but I still don't have ssize_t
.
Where is it defined?
ssize_t
is defined in sys/types.h
.
Per the POSIX documentation:
NAME
sys/types.h - data types
SYNOPSIS
#include <sys/types.h>
DESCRIPTION
The header shall define at least the following types:
...
ssize_t
Used for a count of bytes or an error indication.
(https://stackoverflow.com/a/29984840/6872717):
The division of the POSIX and C header in fine grained files probably comes from the old days when compilation might take a long time, and adding unnecesary header files made the time longer.
If you only need the OS types, say for the prototypes of your functions, then just
#include <sys/types.h>
. However if you need the function definitions, then you#include <unistd.h>
or any of the other system headers, as needed.
Either #include <unistd.h>
for many POSIX functions, or just #include <sys/types.h>
for a small header that contains the type.