Unknown type name 'ssize_t'

Viewed 2059

I am currently experiencing the error

Unknown type name 'ssize_t'

I had a look at Where is ssize_t defined in Linux? but the error remained.

I added the

#include <sys/types.h>

My function is

ssize_t ss_size(sparse_set_ptr sparse_set)
{
    return false;
}

What could be the cause of the problem and can it be fixed? Also I am running C Executable Language Standard: C99

3 Answers

From `man ssize_t:

ssize_t  
    Include:  <sys/types.h>.   Alternatively, <aio.h>, <monetary.h>,
    <mqueue.h>, <stdio.h>, <sys/msg.h>, <sys/socket.h>, <sys/uio.h>,
    or <unistd.h>.

Try all these one by one, with one of them it should work.

Note that even if you include <sys/types.h>, the type might not be defined if you specify a strict C standard with GCC (-std=c99) rather than the GNU variant (-std=gnu99). In fact, you don't need to explicitly include <sys/types.h> with POSIX 2008 (2018) or the prior version, POSIX 2004; it is effectively included automatically.

If you're including <sys/types.h> and still see the problem, then you need to enable the POSIX extensions, probably with #define _XOPEN_SOURCE 700 — the number's easier to remember than #define _POSIX_C_SOURCE 200809L which is a valid alternative. Both these select POSIX 2008; there are other values for other versions of POSIX. There are a few subtle differences between X/Open and POSIX (X/Open might till specify a few things that POSIX does not), but they're minimal and seldom relevant. The #define must appear before any system header is included. It could be specified on the command line as -D_XOPEN_SOURCE=700.

You have to decide which standard you want to use: C99 or Posix.

If you want to use the type ssize_t, then you have to define (activate) that standard in your sources, see man feature_test_macros.

But beware, if you activate any standard, which enables the desired Posix standard, you're not pure C99 anymore.

Related