?
This document uses PHP Chinese website manual Release
在頭文件<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以來(lái)) |
1)復(fù)制src指向的對(duì)象中的字符到dest指向的對(duì)象。 兩個(gè)對(duì)象都被解釋為無(wú)符號(hào)字符數(shù)組。 這些對(duì)象可能會(huì)重疊:復(fù)制發(fā)生就像將這些字符復(fù)制到一個(gè)臨時(shí)字符數(shù)組,然后將這些字符從該數(shù)組復(fù)制到dest一樣。
如果訪問(wèn)超出dest數(shù)組的末尾,則行為未定義。如果dest
或者src
其中之一是空指針,行為是未定義的。
2)同(1)中,檢測(cè)在運(yùn)行時(shí)以下錯(cuò)誤時(shí)除外,它歸零出整個(gè)目標(biāo)范圍[dest, dest+destsz)
(如果兩個(gè)dest
和destsz
是有效的),并調(diào)用當(dāng)前安裝的約束處理函數(shù):
dest
或者src
是空指針
destsz
或count
大于RSIZE_MAX
count
大于destsz
(會(huì)發(fā)生緩沖區(qū)溢出)
如果由dest <count <= destsz指向的字符數(shù)組的大小,行為是未定義的; 換句話說(shuō),destsz的錯(cuò)誤值不會(huì)暴露即將發(fā)生的緩沖區(qū)溢出。 作為所有邊界檢查函數(shù),只有當(dāng)__STDC_LIB_EXT1__由實(shí)現(xiàn)定義并且用戶(hù)在包含string.h之前將__STDC_WANT_LIB_EXT1__定義為整數(shù)常量1時(shí),memmove_s才能保證可用。
dest | - | 指向要復(fù)制到的對(duì)象的指針 |
---|---|---|
destsz | - | 在目標(biāo)中修改的最大字節(jié)數(shù)(通常是目標(biāo)對(duì)象的大?。?/p> |
src | - | 指向要從中復(fù)制的對(duì)象的指針 |
count | - | 要復(fù)制的字節(jié)數(shù) |
1)返回一份dest
副本
2)成功時(shí)返回零,錯(cuò)誤時(shí)返回非零值。 同樣出錯(cuò)的是,如果dest不是空指針且destsz有效,則將destsz零字節(jié)寫(xiě)入目標(biāo)數(shù)組。
memmove
可用于設(shè)置由分配函數(shù)獲得的對(duì)象的有效類(lèi)型。
盡管被指定為“仿佛”使用了臨時(shí)緩沖區(qū),但該函數(shù)的實(shí)際實(shí)現(xiàn)不會(huì)產(chǎn)生開(kāi)銷(xiāo)或雙重復(fù)制或額外的內(nèi)存。 一種常用的方法(glibc和bsd libc)是如果目的地在源之前開(kāi)始,則從緩沖區(qū)的開(kāi)始向前復(fù)制字節(jié),否則從最后向后復(fù)制字節(jié),在沒(méi)有重疊的情況下回退到效率更高的memcpy 所有。
在嚴(yán)格別名禁止檢查與兩種不同類(lèi)型的值相同的內(nèi)存的情況下,memmove
可以用來(lái)轉(zhuǎn)換這些值。
#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標(biāo)準(zhǔn)(ISO / IEC 9899:2011):
7.24.2.2移動(dòng)功能(p:363)
K.3.7.1.2 memmove_s函數(shù)(p:615)
C99標(biāo)準(zhǔn)(ISO / IEC 9899:1999):
7.21.2.2移動(dòng)功能(p:326)
C89 / C90標(biāo)準(zhǔn)(ISO / IEC 9899:1990):
4.11.2.2 memmove函數(shù)
memcpymemcpy_s(C11) | 將一個(gè)緩沖區(qū)復(fù)制到另一個(gè)(功能) |
---|---|
wmemmovewmemmove_s(C95)(C11) | 在兩個(gè)可能重疊的數(shù)組之間復(fù)制一定數(shù)量的寬字符(函數(shù)) |
| memmove的C ++文檔 |
本文檔系騰訊云云+社區(qū)成員共同維護(hù),如有問(wèn)題請(qǐng)聯(lián)系 yunjia_community@tencent.com
在頭文件<wctype.h>中定義 | ||
---|---|---|
int iswdigit(wint_t ch); | (自C95以來(lái)) |
檢查給定的寬字符是否對(duì)應(yīng)(如果縮小)十個(gè)十進(jìn)制數(shù)字字符0123456789中的一個(gè)。
CH | - | 寬字符 |
---|
如果寬字符是數(shù)字字符,則為非零值,否則為零。
iswdigit
與iswxdigit
是唯一不受當(dāng)前安裝的C語(yǔ)言環(huán)境影響的標(biāo)準(zhǔn)寬字符分類(lèi)函數(shù)。
一些語(yǔ)言環(huán)境提供了檢測(cè)非ASCII數(shù)字的附加字符類(lèi)。
#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標(biāo)準(zhǔn)(ISO / IEC 9899:2011):
7.30.2.1.5 iswdigit函數(shù)(p:449)
C99標(biāo)準(zhǔn)(ISO / IEC 9899:1999):
7.25.2.1.5 iswdigit函數(shù)(p:395)
isdigit | 檢查一個(gè)字符是否是一個(gè)數(shù)字(功能) |
---|
| 用于iswdigit的C ++文檔 |
ASCII 值 (十六進(jìn)制) | 字符 | 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 |