?
Ce document utilise Manuel du site Web PHP chinois Libérer
在頭文件<string.h>中定義 | ||
---|---|---|
void * memmove(void * dest,const void * src,size_t count); | (1) | |
errno_t memmove_s(void * dest,rsize_t destsz,const void * src,rsize_t count); | (2) | (自C11以來) |
1)復制src指向的對象中的字符到dest指向的對象。 兩個對象都被解釋為無符號字符數(shù)組。 這些對象可能會重疊:復制發(fā)生就像將這些字符復制到一個臨時字符數(shù)組,然后將這些字符從該數(shù)組復制到dest一樣。
如果訪問超出dest數(shù)組的末尾,則行為未定義。如果dest
或者src
其中之一是空指針,行為是未定義的。
2)同(1)中,檢測在運行時以下錯誤時除外,它歸零出整個目標范圍[dest, dest+destsz)
(如果兩個dest
和destsz
是有效的),并調(diào)用當前安裝的約束處理函數(shù):
dest
或者src
是空指針
destsz
或count
大于RSIZE_MAX
count
大于destsz
(會發(fā)生緩沖區(qū)溢出)
如果由dest <count <= destsz指向的字符數(shù)組的大小,行為是未定義的; 換句話說,destsz的錯誤值不會暴露即將發(fā)生的緩沖區(qū)溢出。 作為所有邊界檢查函數(shù),只有當__STDC_LIB_EXT1__由實現(xiàn)定義并且用戶在包含string.h之前將__STDC_WANT_LIB_EXT1__定義為整數(shù)常量1時,memmove_s才能保證可用。
dest | - | 指向要復制到的對象的指針 |
---|---|---|
destsz | - | 在目標中修改的最大字節(jié)數(shù)(通常是目標對象的大小) |
src | - | 指向要從中復制的對象的指針 |
count | - | 要復制的字節(jié)數(shù) |
1)返回一份dest
副本
2)成功時返回零,錯誤時返回非零值。 同樣出錯的是,如果dest不是空指針且destsz有效,則將destsz零字節(jié)寫入目標數(shù)組。
memmove
可用于設置由分配函數(shù)獲得的對象的有效類型。
盡管被指定為“仿佛”使用了臨時緩沖區(qū),但該函數(shù)的實際實現(xiàn)不會產(chǎn)生開銷或雙重復制或額外的內(nèi)存。 一種常用的方法(glibc和bsd libc)是如果目的地在源之前開始,則從緩沖區(qū)的開始向前復制字節(jié),否則從最后向后復制字節(jié),在沒有重疊的情況下回退到效率更高的memcpy 所有。
在嚴格別名禁止檢查與兩種不同類型的值相同的內(nèi)存的情況下,memmove
可以用來轉換這些值。
#define __STDC_WANT_LIB_EXT1__ 1#include <stdio.h>#include <stdint.h>#include <inttypes.h>#include <string.h>#include <stdlib.h> int main(void){ char str[] = "1234567890"; puts(str); memmove(str+4, str+3, 3); // copy from [4,5,6] to [5,6,7] puts(str); // setting effective type of allocated memory to be int int *p = malloc(3*sizeof(int)); // allocated memory has no effective type int arr[3] = {1,2,3}; memmove(p,arr,3*sizeof(int)); // allocated memory now has an effective type // reinterpreting data double d = 0.1;// int64_t n = *(int64_t*)(&d); // strict aliasing violation int64_t n; memmove(&n, &d, sizeof d); // OK printf("%a is %" PRIx64 " as an int64_t\n", d, n); #ifdef __STDC_LIB_EXT1__ set_constraint_handler_s(ignore_handler_s); char src[] = "aaaaaaaaaa"; char dst[] = "xyxyxyxyxy"; int r = memmove_s(dst,sizeof dst,src,5); printf("dst = \"%s\", r = %d\n", dst,r); r = memmove_s(dst,5,src,10); // count is greater than destsz printf("dst = \""); for(size_t ndx=0; ndx<sizeof dst; ++ndx) { char c = dst[ndx]; c ? printf("%c", c) : printf("\\0"); } printf("\", r = %d\n", r);#endif}
可能的輸出:
123456789012344568900x1.999999999999ap-4 is 3fb999999999999a as an int64_t dst = "aaaaayxyxy", r = 0dst = "\0\0\0\0\0yxyxy", r = 22
C11標準(ISO / IEC 9899:2011):
7.24.2.2移動功能(p:363)
K.3.7.1.2 memmove_s函數(shù)(p:615)
C99標準(ISO / IEC 9899:1999):
7.21.2.2移動功能(p:326)
C89 / C90標準(ISO / IEC 9899:1990):
4.11.2.2 memmove函數(shù)
memcpymemcpy_s(C11) | 將一個緩沖區(qū)復制到另一個(功能) |
---|---|
wmemmovewmemmove_s(C95)(C11) | 在兩個可能重疊的數(shù)組之間復制一定數(shù)量的寬字符(函數(shù)) |
| memmove的C ++文檔 |
本文檔系騰訊云云+社區(qū)成員共同維護,如有問題請聯(lián)系 yunjia_community@tencent.com
在頭文件<wctype.h>中定義 | ||
---|---|---|
int iswdigit(wint_t ch); | (自C95以來) |
檢查給定的寬字符是否對應(如果縮?。┦畟€十進制數(shù)字字符0123456789中的一個。
CH | - | 寬字符 |
---|
如果寬字符是數(shù)字字符,則為非零值,否則為零。
iswdigit
與iswxdigit
是唯一不受當前安裝的C語言環(huán)境影響的標準寬字符分類函數(shù)。
一些語言環(huán)境提供了檢測非ASCII數(shù)字的附加字符類。
#include <stdio.h>#include <wctype.h>#include <wchar.h>#include <locale.h> void test(wchar_t a3, wchar_t u3, wchar_t j3){ printf(" '%lc' '%lc' '%lc'\n", a3, u3, j3); printf("iswdigit %d %d %d\n", !!iswdigit(a3), !!iswdigit(u3), !!iswdigit(j3)); printf("jdigit: %d %d %d\n", !!iswctype(a3, wctype("jdigit")), !!iswctype(u3, wctype("jdigit")), !!iswctype(j3, wctype("jdigit")));} int main(void){ wchar_t a3 = L'3'; // the ASCII digit 3 wchar_t u3 = L'三'; // the CJK numeral 3 wchar_t j3 = L'3'; // the fullwidth digit 3 setlocale(LC_ALL, "en_US.utf8"); puts("In American locale:"); test(a3, u3, j3); setlocale(LC_ALL, "ja_JP.utf8"); puts("\nIn Japanese locale:"); test(a3, u3, j3);}
輸出:
In American locale: '3' '三' '3'iswdigit 1 0 0jdigit: 0 0 0 In Japanese locale: '3' '三' '3'iswdigit 1 0 0jdigit: 0 0 1
C11標準(ISO / IEC 9899:2011):
7.30.2.1.5 iswdigit函數(shù)(p:449)
C99標準(ISO / IEC 9899:1999):
7.25.2.1.5 iswdigit函數(shù)(p:395)
isdigit | 檢查一個字符是否是一個數(shù)字(功能) |
---|
| 用于iswdigit的C ++文檔 |
ASCII 值 (十六進制) | 字符 | iscntrl iswcntrl. | isprint iswprint. | isspace iswspace. | isblank iswblank. | isgraph iswgraph. | ispunct iswpunct. | isalnum iswalnum. | isalpha iswalpha. | isupper iswupper. | islower iswlower. | isdigit iswdigit. | isxdigit iswxdigit. | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 - 8 | 0x00-0x08 | 控制碼 (NUL, etc.) | ≠0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
9 | 0x09 | tab (\t) | ≠0 | 0 | ≠0 | ≠0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
10 - 13 | 0x0A-0x0D | 空格 (\n,\v,\f,\r) | ≠0 | 0 | ≠0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
14 - 31 | 0x0E-0x1F | 控制碼 | ≠0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
32 | 0x20 | space | 0 | ≠0 | ≠0 | ≠0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
33 - 47 | 0x21-0x2F | !"#$%&'()*+,-./ | 0 | ≠0 | 0 | 0 | ≠0 | ≠0 | 0 | 0 | 0 | 0 | 0 | 0 |
48 - 57 | 0x30-0x39 | 0123456789 | 0 | ≠0 | 0 | 0 | ≠0 | 0 | ≠0 | 0 | 0 | 0 | ≠0 | ≠0 |
58 - 64 | 0x3a-0x40 | :;<=>?@ | 0 | ≠0 | 0 | 0 | ≠0 | ≠0 | 0 | 0 | 0 | 0 | 0 | 0 |
65 - 70 | 0x41-0x46 | ABCDEF | 0 | ≠0 | 0 | 0 | ≠0 | 0 | ≠0 | ≠0 | ≠0 | 0 | 0 | ≠0 |
71 - 90 | 0x47-0x5A | GHIJKLMNOPQRSTUVWXYZ | 0 | ≠0 | 0 | 0 | ≠0 | 0 | ≠0 | ≠0 | ≠0 | 0 | 0 | 0 |
91 - 96 | 0x5B-0x60 | []^_` | 0 | ≠0 | 0 | 0 | ≠0 | ≠0 | 0 | 0 | 0 | 0 | 0 | 0 | | ||||||||||||
97 -102 | 0x61-0x66 | abcdef | 0 | ≠0 | 0 | 0 | ≠0 | 0 | ≠0 | ≠0 | 0 | ≠0 | 0 | ≠0 |
103-122 | 0x67-0x7A | ghijklmnopqrstuvwxyz | 0 | ≠0 | 0 | 0 | ≠0 | 0 | ≠0 | ≠0 | 0 | ≠0 | 0 | 0 |
123-126 | 0x7B-0x7E | {|}~ | 0 | ≠0 | 0 | 0 | ≠0 | ≠0 | 0 | 0 | 0 | 0 | 0 | 0 |
127 | 0x7F | 退格 (DEL) | ≠0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |