gpt4 book ai didi

c - 为什么 memset、memchr 等内存函数在 string.h 中,而在 stdlib.h 中却没有另一个 mem 函数?

转载 作者:IT王子 更新时间:2023-10-28 23:28:31 36 4
gpt4 key购买 nike

我想知道,为什么这样的功能:
-memset
-memmov
-memchr
-memcpy

存在于string.h头文件中,但不存在于stdlib.h文件中,其中还有其他标准内存函数如动态内存分配:malloc、calloc、realloc、free。

也许将它们合并到一个标题中会更好?你怎么看待这件事?我不明白,为什么一组内存函数与其他函数分开并存在于字符串头(string.h)中。

最佳答案

因为实际上 string.h 被定义为一个标准头文件,它声明了处理字符数组而不仅仅是字符串的函数。 memcpymemset 等函数接受的参数被视为指向字符数组类型对象的第一个元素的指针。

(C99, 7.21.1p1) The header < string.h > declares one type and several functions, and defines one macro useful for manipulating arrays of character type and other objects treated as arrays of character type.

关于c - 为什么 memset、memchr 等内存函数在 string.h 中,而在 stdlib.h 中却没有另一个 mem 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9782126/

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