How to use C language to realize the function void * memmove (void * dest,const void * src,size_t n)
Today, I will talk to you about how to use C language to achieve the function void * memmove (void * dest,const void * src,size_t n). Many people may not know much about it. In order to make you understand better, the editor has summarized the following for you. I hope you can get something according to this article.
This function exists in the C _ src + standard library function, which is used to copy n bytes of data pointed to by src to the dest location. There is another function memcpy in the standard library function, which is also used to implement memory copying, but it does not consider the problem of interval overlap and may cause overlapping errors in the copying process.
On the other hand, memmove gives some measures to prevent copy errors in response to the appeal problem:
(1) when the first address of the source memory is equal to the first address of the destination memory, no copy is made
(2) when the first address of the source memory is greater than the first address of the destination memory, the forward copy is performed.
(3) reverse copy is performed when the first address of the source memory is less than the first address of the destination memory.
The following is a specific implementation of memmove, about memcpy can refer to the library function implementation or related materials.
Void * memmove (void * dest,const void * src, size_t n) {if (NULL = = dest | | src = = NULL) {cerr