|
@@ -51,9 +51,20 @@ int snprintf( char *buffer, size_t buf_size, const char *format, ... );//可变
|
|
|
## `memcpy` 函数
|
|
|
### 作用
|
|
|
> En
|
|
|
-> Copies count bytes from the object pointed to by src to the object pointed to by dest. Both objects are reinterpreted as arrays of unsigned char. If the objects overlap, the behavior is undefined. If either dest or src is a potentially-overlapping subobject (e.g., a field in a C-compatible struct) or is not TriviallyCopyable (e.g., scalar, C-compatible struct, or an array thereof), the behavior is undefined. If count is zero, the function does nothing.
|
|
|
-> Ch
|
|
|
-> 将src指向的对象的count个字节复制到dest指向的对象。两个对象都被重新解释为无符号字符数组。如果对象重叠,则行为是未定义的。如果dest或src是潜在重叠的子对象(例如,C兼容结构中的字段)或不是TriviallyCopyable(例如,标量,C兼容结构或其数组),则行为是未定义的。如果count为零,则函数不执行任何操作。
|
|
|
+> Copies count bytes from the object pointed to by src to the object pointed to by dest.
|
|
|
+> Both objects are reinterpreted as arrays of unsigned char.
|
|
|
+> If the objects overlap, the behavior is undefined.
|
|
|
+> If either dest or src is a potentially-overlapping subobject
|
|
|
+> (e.g., a field in a C-compatible struct) or is not TriviallyCopyable
|
|
|
+> (e.g., scalar, C-compatible struct, or an array thereof),
|
|
|
+> the behavior is undefined. If count is zero, the function does nothing.
|
|
|
+> Ch
|
|
|
+> 将src指向的对象的count个字节复制到dest指向的对象。
|
|
|
+> 两个对象都被重新解释为无符号字符数组。
|
|
|
+> 如果对象重叠,则行为是未定义的。
|
|
|
+> 如果dest或src是潜在重叠的子对象(例如,C兼容结构中的字段)
|
|
|
+> 或不是TriviallyCopyable(例如,标量,C兼容结构或其数组),
|
|
|
+> 则行为是未定义的。如果count为零,则函数不执行任何操作。
|
|
|
|
|
|
### 语法
|
|
|
```c++
|
|
@@ -61,4 +72,18 @@ void *memcpy(void *dest, const void *src, size_t count);
|
|
|
```
|
|
|
|
|
|
### 参数
|
|
|
+- dest: 指向目标对象的指针
|
|
|
+- src: 指向源对象的指针
|
|
|
+- count: 要被复制的字节数
|
|
|
|
|
|
+### 实现
|
|
|
+```c++
|
|
|
+void *memcpy(void *dest, const void *src, size_t count)
|
|
|
+{
|
|
|
+ char *d = dest;
|
|
|
+ const char *s = src;
|
|
|
+ while (count--)
|
|
|
+ *d++ = *s++;
|
|
|
+ return dest;
|
|
|
+}
|
|
|
+```
|