Hello,
I was reading the musl source code, and I was surprised by the implementation of memset() (https://git.etalabs.net/cgit/musl/tr...tring/memset.c)
Reminder: The prototype of the function is
Code:
void *memset(void *dest, int c, size_t n)
and the s variable represents
Code:
unsigned char *s = dest;
The last line of the function is
Code:
for (; n; n--, s++) *s = c;
which should be enough for the complete implementation of memset, since it sets the whole array with the value c.
But instead of that, the function first manually sets the beginning and the end of the array, if 1 < n <= 8; then, only if __GNUC__ is defined, will continue to do the same for 9 < n <= 28 with an offset of 4.
As you can read, my understanding for what this function does, and, most importantly, why it is like that, is limited, and I would gladly like to read an explanation about it, other than the source code comments.
Best regards.