1

What is the difference between these two? I'm led to believe that they are the same thing since when I declare

ssize_t size;

without using namespace std I get a compilation error. Changing the declaration to std::size_t size; fixes this.

marti
  • 69
  • 7

1 Answers1

1

size_t the type of sizeof, which is large enough to express the size of any C++ object or array index. It's unsigned type.

ssize_t is signed type, which accounts for -1 as error return type. A good reference for ssize_t is: https://man7.org/linux/man-pages/man7/system_data_types.7.html

   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>.

          Used for a count of bytes or an error indication.
          According to POSIX, it shall be a signed integer type
          capable of storing values at least in the range [-1,
          SSIZE_MAX], and the implementation shall support one or
          more programming environments where the width of ssize_t
          is no greater than the width of the type long.
artm
  • 17,291
  • 6
  • 38
  • 54