C 标准库函数——memset
1、Synopsis
#include <string.h>
void *memset(void *s, int c, size_t n);
2、Description
The memset function copies the value of c (converted to unsigned char) into each of the first n characters of the object pointed to by s.
3、Returns
The memset function returns the value of s.
4、Function
void *(memset)(void *s, int c, size_t n)
{
const unsigned char uc = c;
unsigned char *su;
for (su = s; 0 < n; --n)
*su = uc;
return (s);
}
I choose unsigned char as the working type within memset in the off chance that some implementation might generate an overflow storing certain int values in the other character types.