提问人:marti 提问时间:12/30/2021 更新时间:12/30/2021 访问量:1597
ssize_t 和 std::size_t 有什么区别?[复制]
What is the difference between ssize_t and std::size_t? [duplicate]
问:
这两者有什么区别?自从我宣布以来,我就被引导相信它们是一回事
ssize_t size;
没有我得到编译错误。更改声明以解决此问题。using namespace std
std::size_t size;
答:
1赞
artm
12/30/2021
#1
size_t
的类型,它足够大,可以表示任何 C++ 对象或数组索引的大小。它是无符号类型。sizeof
ssize_t
是有符号类型,其中 -1 作为错误返回类型。一个很好的参考是:https://man7.org/linux/man-pages/man7/system_data_types.7.htmlssize_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>.
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.
评论
std::ssize_t