【问题标题】:What is the difference between ssize_t and std::size_t? [duplicate]ssize_t 和 std::size_t 有什么区别? [复制]
【发布时间】:2021-12-30 00:37:11
【问题描述】:

这两者有什么区别?自从我宣布之后,我就被引导相信它们是同一回事

ssize_t size;

没有using namespace std 我得到一个编译错误。将声明更改为 std::size_t size; 可以解决此问题。

【问题讨论】:

标签: c++ namespaces std size-t ssize-t


【解决方案1】:

size_t sizeof 的类型,大到足以表达任何 C++ 对象或数组索引的大小。是无符号类型。

ssize_t 为有符号类型,错误返回类型为-1。 ssize_t 的一个很好的参考是: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.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-03-09
    • 2020-05-06
    • 2019-09-04
    • 1970-01-01
    • 2014-03-15
    • 1970-01-01
    相关资源
    最近更新 更多