[英]What will happen we pass -1 as value for 3rd parameter in strncmp() ie. n number bytes of bytes to compare?
I have three questions, 我有三个问题,
If I use memcmp instead of strncmp, I m getting "inside else" output in both ARM and PPC. 如果我使用memcmp而不是strncmp,那么我在ARM和PPC中都将获得“ inside else”输出。 How and why?
如何以及为什么?
char str[10]; memset(str,'\\0',sizeof(str)); printf("str:%s ,len:%d\\n\\r",str,strlen(str)); if(strncmp(str,"Maximum",(strlen(str)-1)) == 0) { printf("inside if\\n\\r"); } else { printf("inside else\\n\\r"); }
Output in ppc 以ppc输出
str: ,len:0
inside else
Output in arm 手臂输出
str: ,len:0
inside if
What will happen we pass -1 as value for 3rd parameter in strncmp()
会发生什么,我们将-1作为strncmp()中第三个参数的值传递
Assuming the 3rd parameter is defined a being of size_t
and furthermore assuming size_t
is defined as unsigned
integer, passing in -1
will result in a "wrap-around" and the function will receiving the value of SIZE_MAX
. 假设第三个参数定义为
size_t
,并且还假设size_t
被定义为unsigned
整数,则传入-1
将导致“环绕”,并且函数将接收SIZE_MAX
的值。 On a 32bit system this probably would be 0xffffffff
. 在32位系统上,这可能是
0xffffffff
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.