这是代码
而这样写就是对的, count 返回的不就是数值类型么?
这里有啥知识点?求大牛解惑啊 - -
而这样写就是对的, count 返回的不就是数值类型么?
这里有啥知识点?求大牛解惑啊 - -
|
1
count 方法返回的是 NSUInteger ,我的 index 是 NSInteger
这两种数据类型比较会存在问题吧 |
|
fogislandNov 30, 2015
2
@finab 这是 C 语言的范畴了, int 会被强转为 uint ,因此 -1 > _group.count ;
直接写 -1 > 2 返回 false, 是因为常数的默认类型都是 int , 不会发生类型转换 |
|
loveuqianNov 30, 2015 via iPhone
3
为啥你自定义类 view 是小写字母开头
|
|
4
@fogisland 我比较好奇的是
int 与 uint 比较,会把 int 转成 uint, 而不是将 uint 转成 int - - NSLog(@"%u", -1); // 输出 4294967295 |
|
fogislandNov 30, 2015
6
@finab
给你个链接看看: https://www.securecoding.cert.org/confluence/display/cplusplus/INT02-CPP.+Understand+integer+conversion+rules "If the operand that has unsigned integer type has rank greater than or equal to the rank of the type of the other operand, the operand with signed integer type is converted to the type of the operand with unsigned integer type." |
|
wizardforcelNov 30, 2015 via Android
8
|
|
surfire91Nov 30, 2015
9
@wizardforcel 这还不是溢出?
|
|
wezzardNov 30, 2015
10
lou zhu zai diao yu.
|