memmove
Posted: Wed Oct 16, 2002 7:51 pm
Hi all,
I just have a question about memmove(). The prototype for this finction is
void * memmove ( void * dest, const void * src, size_t num );
Really this function is only good for working on a buffer that is both the dest and src because it is impossible for two different variables to have overlapping addresses, unless one is a reference to another, which would be the same as the dest and src being that same.
So from the prototype you would expect that src would not be modified because it is going in as const, but what if the following situation happens?
Let's say that we do this
char* pDst = "This is a string!...";
memmove(pDst+8, pDst+5, 12);
This would produce the following string
"This is is a string!"
However now src has been modified, not by it's reference but none the less it is still modified!
Becasue src is pDst+5 and goes for 12 bytes from byte 3 of the copy, the src is changed.
So can someone tell me why the prototype is const void* src, isn't this incorrect?
I just have a question about memmove(). The prototype for this finction is
void * memmove ( void * dest, const void * src, size_t num );
Really this function is only good for working on a buffer that is both the dest and src because it is impossible for two different variables to have overlapping addresses, unless one is a reference to another, which would be the same as the dest and src being that same.
So from the prototype you would expect that src would not be modified because it is going in as const, but what if the following situation happens?
Let's say that we do this
char* pDst = "This is a string!...";
memmove(pDst+8, pDst+5, 12);
This would produce the following string
"This is is a string!"
However now src has been modified, not by it's reference but none the less it is still modified!
Becasue src is pDst+5 and goes for 12 bytes from byte 3 of the copy, the src is changed.
So can someone tell me why the prototype is const void* src, isn't this incorrect?