c 语言memmove,memmove - [ C语言中文开发手册 ] - 在线原生手册 - php中文网
在头文件中定义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指向的对象。 两个对象都被解释为无符号字符数组。 这些对象可能会重叠:复制发生就像将这些字符复制到一个临时字符数组,然后将这些字符从该数组复制到dest一样。
如果访问超出dest数组的末尾,则行为未定义。如果dest或者src其中之一是空指针,行为是未定义的。
2)与(1)相同,除了在运行时检测到以下错误,它会将整个目标范围[dest,dest + destsz)清零(如果dest和destsz都有效)并调用当前安装的约束处理函数:
dest或者src是空指针
destsz或count大于RSIZE_MAX
count大于destsz(会发生缓冲区溢出)
如果由dest
参数
dest-指向要复制到的对象的指针destsz-在目标中修改的最大字节数(通常是目标对象的大小)
src-指向要从中复制的对象的指针
count-要复制的字节数
返回值
1)返回一份 dest 副本
2)成功时返回零,错误时返回非零值。 同样出错的是,如果dest不是空指针且destsz有效,则将destsz零字节写入目标数组。
注意
memmove 可用于设置由分配函数获得的对象的有效类型。
尽管被指定为“as if”使用了临时缓冲区,但该函数的实际实现不会产生开销或双重复制或额外的内存。 一种常用的方法(glibc和bsd libc)是如果目的地在源之前开始,则从缓冲区的开始向前复制字节,否则从最后向后复制字节,在没有重叠的情况下回退到效率更高的memcpy 所有。
在严格别名禁止检查与两种不同类型的值相同的内存的情况下,memmove可以用来转换这些值。
例
#define __STDC_WANT_LIB_EXT1__ 1#include #include #include #include #include
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
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函数(p:615)
C99标准(ISO / IEC 9899:1999):7.21.2.2移动功能(p:326)
C89 / C90标准(ISO / IEC 9899:1990):4.11.2.2 memmove函数
扩展内容
memcpymemcpy_s(C11)将一个缓冲区复制到另一个(功能)wmemmovewmemmove_s(C95)(C11)在两个可能重叠的数组之间复制一定数量的宽字符(函数)
| memmove的C ++文档 |
本文档系腾讯云云+社区成员共同维护,如有问题请联系 yunjia_community@tencent.com
在头文件中定义int iswdigit(wint_t ch);(自C95以来)
检查给定的宽字符是否对应(如果缩小)十个十进制数字字符0123456789中的一个。
参数
CH-宽字符
返回值
如果宽字符是数字字符,则为非零值,否则为零。
注意
iswdigit与iswxdigit是唯一不受当前安装的C语言环境影响的标准宽字符分类函数。
例
一些语言环境提供了检测非ASCII数字的附加字符类。
#include #include #include #include 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函数(p:449)
C99标准(ISO / IEC 9899:1999):7.25.2.1.5 iswdigit函数(p:395)
扩展内容
isdigit检查一个字符是否是一个数字(功能)
| 用于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 - 80x00-0x08控制码 (NUL, etc.)≠000000000000
90x09tab (\t)≠00≠0≠000000000
10 - 130x0A-0x0D空格 (\n,\v,\f,\r)≠00≠0000000000
14 - 310x0E-0x1F控制码≠000000000000
320x20space0≠0≠0≠000000000
33 - 470x21-0x2F!"#$%&'()*+,-./0≠000≠0≠0000000
48 - 570x30-0x3901234567890≠000≠00≠0000≠0≠0
58 - 640x3a-0x40:;<=>?@0≠000≠0≠0000000
65 - 700x41-0x46ABCDEF0≠000≠00≠0≠0≠000≠0
71 - 900x47-0x5AGHIJKLMNOPQRSTUVWXYZ0≠000≠00≠0≠0≠0000
91 - 960x5B-0x60[]^_` | 0 | ≠0 | 0 | 0 | ≠0 | ≠0 | 0 | 0 | 0 | 0 | 0 | 0 |
97 -1020x61-0x66abcdef0≠000≠00≠0≠00≠00≠0
103-1220x67-0x7Aghijklmnopqrstuvwxyz0≠000≠00≠0≠00≠000
123-1260x7B-0x7E{|}~0≠000≠0≠0000000
1270x7F退格 (DEL)≠000000000000
c 语言memmove,memmove - [ C语言中文开发手册 ] - 在线原生手册 - php中文网相关推荐
- php中的lc_time,LC_TIME - [ C语言中文开发手册 ] - 在线原生手册 - php中文网
在头文件中定义#define LC_ALL / *实现定义* / #define LC_COLLATE / *实现定义* / #define LC_CTYPE / *实现定义* / #define L ...
- cbrt c语音_isgraph - [ C语言中文开发手册 ] - 在线原生手册 - php中文网
在头文件中定义int isgraph(int ch); 检查给定字符是否具有图形表示形式,即它是数字(0123456789),大写字母(ABCDEFGHIJKLMNOPQRSTUVWXYZ),小写字母 ...
- c语言 strncat,strncat - [ C语言中文开发手册 ] - 在线原生手册 - php中文网
在头文件中定义(1) char * strncat(char * dest,const char * src,size_t count);(直到C99) char * strncat(char * r ...
- c语言fsetpos是什么,fsetpos - [ C语言中文开发手册 ] - 在线原生手册 - php中文网
在头文件中定义int fsetpos(FILE * stream,const fpos_t * pos); stream根据指向的值设置文件流的文件位置指示符和多字节解析状态(如果有)pos. 除了建 ...
- c语言中mw shl code,cacoshl - [ C语言中文开发手册 ] - 在线原生手册 - php中文网
在头文件中定义float complex cacoshf( float complex z );(1)(since C99) double complex cacosh( dou ...
- php vprintf,vprintf - [ C语言中文开发手册 ] - 在线原生手册 - php中文网
格式-指向以空字符结尾的字符串的指针,指定如何解释数据.格式字符串由普通的多字节字符(%除外)组成,它们被原样复制到输出流和转换规范中.每个转换规范具有以下格式:介绍%字符(可选)一个或多个标志,用于 ...
- c语言L文件,frexpl - [ C语言中文开发手册 ] - 在线原生手册 - php中文网
在头文件中定义float frexpf(float arg,int * exp);(1)(自C99以来) double frexp(double arg,int * exp);(2) long dou ...
- c语言isfinite_csqrtf - [ C语言中文开发手册 ] - 在线原生手册 - php中文网
在头文件中定义float complex csqrtf(float complex z);(1)(自C99以来) double complex csqrt( double complex z ); ...
- php atan2,atan2l - [ C语言中文开发手册 ] - 在线原生手册 - php中文网
在头文件中定义float atan2f( float y, float x );(1)(since C99) double atan2( double y, double x ) ...
最新文章
- 今日 Paper | 新闻推荐系统;多路编码;知识增强型预训练模型等
- 喜得千金,升级做爸爸喽
- python typing typescript_Python的价值,对比Java/Typescript
- 算法---字符串去重
- VC++实现QPSK调制
- AS3 CookBook学习整理(十七)
- pythonmessage用法_django 消息框架 message使用详解
- 面对一夜狼人杀特殊的游戏机制,取得胜利很难吗?还可以
- bashrc文件中环境变量配置错误,导致linux命令无法正常使用的解决方案
- c语言实参和形参占用存储单元_必须知道的C语言知识细节:函数形参和实参的区别...
- spring的bean范围_Spring Bean范围
- leetcode695. 岛屿的最大面积(dfs)
- java中cookie怎么用_java 中session和cookie的使用
- LightGBM算法解析
- iOS逆向-微信自动添加好友
- 获取硬盘的smart信息
- pod install 时遇到 Automatically assigning platform `iOS` with version `11.0` on target XXX......
- 第四章(1.2)机器学习——在web攻击检测中的应用实践
- 计算机缓存Cache以及Cache Line详解
- vector erase操作