tl;dr; How to reproduce memset
with basic c++?
I am trying to figure out how memset
works , and to see if I can reproduce it within normal c++
using pointers and address.
This is what I've got so far.
void test_memset( void * origin, uint8_t val, size_t size ){
if( size != 1 ){
uint8_t* new_or = (uint8_t*) origin; // casting to uint8_t*
*new_or ^= (*new_or & 0xff); // clearing any remaining data
*new_or ^= val; // assigning the val
new_or++; // incrementing pointer
test_memset_alloc( new_or, val, size-1 ); // recursion
}
}
So the question : What does memset look like in basic c++?
EDIT 1:
Answered here in similar manner, and here a tad bit more verbose. Both answers are better suited than my proposition.
But i would like to see some detailed solutions, that would be able to explain a Mort (the line-of-business developer) or someone with fractuated knowledge, what is happening with more clarification than :"This is frowned upon" or "not a c++ way".