I have a query about memcpy's prototype.
Since the arguments are restricted pointers and according to a restricted pointer only that pointer has access to the object how the function works? and copies the bytes from one pointer to another?
I think overlapping situation is something like :
Code:
#include<stdio.h>
int main(void)
{
char msg[60]="abcdefghijklmnopqrstuvwxyz";
char tmp[60];
strcpy(tmp , msg);
memcpy(tmp+4 , tmp+16 , 10); /* without overlap temp is : abcdqrstuvwxyzopqrstuvwxyz */
strcpy(tmp,msg);
memcpy(tmp+6, tmp+4,10); /* with overlap temp is :
abcdefefefefefefqrstuvwyz */
return 0;
}
for example here :
Code:
// C99 code
void *memcpy(void * restrict dest, const void * restrict src, size_t n)
{
char *d = dest;
const char *s = src;
size_t i;
for (i = 0; i != n; ++i)
d[i] = s[i];
return dest;
}
How the assignment d[i]=s[i] works? since d is restricted.
I am confused when I see the keyword restrict in the function although I know its concept.