- 论坛徽章:
- 0
|
原帖由 std_linux 于 2009-2-26 11:39 发表 ![]()
我的理解是,strlen的功能是得到字符数,也就是一个绝对值,无符号值得范围是 0-65535,总是个正值,
有符号值是 -32767 至 + 32768 ; 65535 大于 32768 ,范围更大。
而返回值用无符号值不好 ...
事实证明,楼主的猜测是错误的
下面是我实际测试的例子,有同样疑问者可以各自测试一下
- [net@localhost tmp]$ cat k.c
- #include <stdio.h>
- int main ()
- {
- int i=0;
- int j=-1;
- unsigned int m=0;
- unsigned int n=0;
- n=j;
- printf("%d,%u\n",j,n);
- if(n>0)
- {
- printf("n > 0\n");
- }
- if(n>m)
- {
- printf("n > m\n");
- }
- }
- [net@localhost tmp]$ gcc k.c ;./a.out
- -1,4294967295
- n > 0
- n > m
- [net@localhost tmp]$
复制代码
- [net@localhost tmp]$ gcc --version
- gcc (GCC) 4.3.2 20081105 (Red Hat 4.3.2-7)
- Copyright (C) 2008 Free Software Foundation, Inc.
- This is free software; see the source for copying conditions. There is NO
- warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
复制代码 |
|