Which header file to include for memset
What do you think about it? I don't understand, why one set of memory functions are separated from others and exist in string header string.
Because actually string. Functions like memcpy and memset take arguments that are treated as pointers to the first element of an object of type array of characters. C99, 7. I wouldn't really think of the string.
Instead, I would think of them as "array" functions, since they operate on the data which is contained within sequences of memory. By contrast, malloc and others , actually provide memory services such as allocation, rather than manipulation of the data within a region of memory. In particular, the functions in string. The other functions might return a pointer to a memory block, but this is actually just one of their parameters e.
Or they return a pointer to the start of a sub-string strtok , or an integer representing a comparison memcmp. On the other hand, stdlib. The design of stdlib. The memory functions just happen to be examples of such fundamental operations. However, other functions like exit and system are also good examples, yet don't apply to memory. Now there are some functions in stdlib. These functions follow the same principles as the string. Such a change would definitely break code.
Also, stdlib. In Pre-Standard C, these functions were indeed defined somewhere else, but neither in stdlib. It still might exist on your system, it certainly still does on OS X as of today. The whole file is only include 'ing string. Besides historical considerations, the separation of data manipulation utilities like those in string.
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. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Why memory functions such as memset, memchr Ask Question. Asked 9 years, 8 months ago. Active 3 years, 4 months ago. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Skip to content. Change Language. Related Articles. Table of Contents. Save Article. Improve Article. Like Article. Previous memset in C with examples. Next What are the default values of static variables in C? Recommended Articles. Article Contributed By :. Easy Normal Medium Hard Expert.
0コメント