Hey. I've been researching into operating system programming.
I am trying to figure out what exactly what each line of code does.
For example, the function below copies chunks of memory from a source to a destination. In order for me to understand how the code works, It is necessary to decipher each line individually.
Code:
unsigned char *memcpy(unsigned char *dest, const unsigned char *src, int count)
{
const char *sp = (const char *)src;
char *dp = (char *)dest;
for(; count != 0; count--) *dp++ = *sp++;
return dest;
}
From what I know already, the following code takes the source's addresses in memory, and maps it onto the destination memory address, thereby copying it.
Code:
for(; count != 0; count--) *dp++ = *sp++;
return dest;
However I do not understand some things.
Firstly,
Code:
char *dp = (char *)dest;
I've never seen anything like the above code. What I do not understand is what the parenthesis does. Common sense would dictate that this is simply assigning the destination to a pointer, however as I do not understand what the purpose of the parentheses is, I cannot fully understand the purpose of this code. Could someone kindly explain this to me?
The other thing I do not understand is at the declaration of the function, the name of the function has a * before it. I do not understand what this does. Does it return the pointer of the return value instead of the actual return value?
Thanks in Advance,
~ShadowzReloaded