Why memory functions such as memset, memchr… are in string.h, but not in stdlib.h with another mem functions?

前端 未结 4 1182
独厮守ぢ
独厮守ぢ 2021-01-30 16:01

I wonder, why such function as:
-memset
-memmov
-memchr
-memcpy

Exist in string.h header file, but not in stdlib.h file, where there are ot

4条回答
  •  清歌不尽
    2021-01-30 16:39

    Besides historical considerations, the separation of data manipulation utilities like those in string.h and system functions like malloc in stdlib.h makes a lot of sense when you consider contexts where an operating system is not a given. Embedded systems may or may not have an RTOS and they may or may not have standard memory allocation available. However, utilities like strcpy and memcpy occupy a similar space in that they do not rely on any external systems and therefore can be run in any context where you can run compiled code. Conceptually and practically it makes sense to put them together, and to separate them from more complex system calls.

提交回复
热议问题