Improve this answer. As coded, your function has implementation defined behavior because c might be out of range for the char type. How else can it possible do without a loop? Is it using an OS api to do it? And even then it would still require a loop. Nik-Lz: the compiler knows about memset and doesn't need to do any analysis on the arguments and can easily generate vector operations.
Admittedly, many compilers will vectorize loops in optimization mode. Given the question asking what the point of memset is, this answer is better than the accepted one imho.
AndersK AndersK This answer should be higher up on the list. Basile Starynkevitch Basile Starynkevitch k 16 16 gold badges silver badges bronze badges. It is nothing but setting the memory to particular value. Here is example code. Vino Vino 91 2 2 silver badges 7 7 bronze badges. Ashit Ashit 49 5 5 bronze badges. How does this answer add value to a 4 year old post with 5 other answers?
I was looking for an answer and I got to know this definition from another source. So thought it would be helpful for other people who are in searching of this one. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name.
Email Required, but never shown. The Overflow Blog. Podcast Explaining the semiconductor shortage, and how it might end. Does ES6 make JavaScript frameworks obsolete? Featured on Meta. Now live: A fully responsive profile. Linked 6. Related Hot Network Questions. Question feed.
Stack Overflow works best with JavaScript enabled. Accept all cookies Customize settings. Learn more. Why memory functions such as memset, memchr Ask Question.
Asked 9 years, 7 months ago. Active 3 years, 4 months ago. Viewed 36k times. I wonder, why such function as: -memset -memmov -memchr -memcpy Exist in string. Improve this question. Rndp13 1 1 gold badge 17 17 silver badges 32 32 bronze badges. This looks like implementation issue with the C library you are using. Other C library may choose to move memcpy to stdlib. My guess, it's purely historical reasons.
That was probably the header file the function was put in when they were first introduced, and to keep maximum backward compatibility the standard committee decided to let them stay there. The C standard library is not a model of consistent design. Add a comment. Active Oldest Votes. Improve this answer. You can pass any object pointer type, but the array elements are in fact interpreted as if they have the type unsigned char. Leandros Leandros Michael Powell Michael Powell 59 6 6 bronze badges.
Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Podcast Explaining the semiconductor shortage, and how it might end. Does ES6 make JavaScript frameworks obsolete? Featured on Meta. Now live: A fully responsive profile.
Linked 1. Related 1. Hot Network Questions. Question feed.
0コメント