gpt4 book ai didi

c - 为什么不考虑将 strnlen() 包含在 C23 中?

转载 作者:行者123 更新时间:2023-12-05 02:28:59 25 4
gpt4 key购买 nike

函数 strdup()strndup() 终于进入了即将到来的 C23 标准:

7.24.6.4 The strdup function

Synopsis

#include <string.h>
char *strdup(const char *s);

The strdup function creates a copy of the string pointed to by s in a space allocated as if by a call to malloc.

Returns
The strdup function returns a pointer to the first character of the duplicate string. The returned pointer can be passed to free. If no space can be allocated the strdup function returns a null pointer.

7.24.6.5 The strndup function

Synopsis

#include <string.h>
char *strndup(const char *s, size_t size);

The strndup function creates a string initialized with no more than size initial characters of the array pointed to by s and up to the first null character, whichever comes first, in a space allocated as if by a call to malloc. If the array pointed to by s does not contain a null within the first size characters, a null is appended to the copy of the array.

Returns
The strndup function returns a pointer to the first character of the created string. The returned pointer can be passed to free. If no space can be allocated the strndup function returns a null pointer.

为什么不考虑包含 POSIX-2008 函数 strnlen

#include <string.h>
size_t strnlen(const char *s, size_t maxlen);

strnlen() 函数应计算 s 指向的数组中字节数中较小的一个,不包括终止 NUL 字符,或值maxlen 参数。 strnlen() 函数永远不会检查 s 指向的数组的 maxlen 个字节。

最佳答案

有趣的是,这个功能是在https://www9.open-std.org/JTC1/SC22/WG14/www/docs/n2351.htm中提出的

它在 2019 年的伦敦 session 上进行了讨论。查看议程: https://www9.open-std.org/JTC1/SC22/WG14/www/docs/n2370.htm

讨论记录可以在https://www9.open-std.org/JTC1/SC22/WG14/www/docs/n2377.pdf找到。 .第 59 页。

由于没有达成共识而被拒绝。

6.33 Sebor, Add strnlen to C2X [N 2351]

...

*Straw poll: Should N2351 be put into C2X?

(11/6/6)

Not clear consensus.

因此没有添加该功能。

关于c - 为什么不考虑将 strnlen() 包含在 C23 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72392985/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com