t*****h 发帖数: 137 | 1 I have a following question about unsigned and int type, and the result
really surprised me.
ubuntu 8.04 and g++ 4.24
Here is the code
#include
using namespace std;
int main()
{
unsigned x = 1;
int k = 1;
if ( (x-k) >= -1 )
cout << "0 >= -1\n";
else
{
cout << "0 < -1\n";
}
return 0;
} |
T*****9 发帖数: 2484 | 2 unsigned int 0最小
【在 t*****h 的大作中提到】 : I have a following question about unsigned and int type, and the result : really surprised me. : ubuntu 8.04 and g++ 4.24 : Here is the code : #include : using namespace std; : int main() : { : unsigned x = 1; : int k = 1;
|
k*****l 发帖数: 177 | 3 回答的真含蓄 :)
这种不同类型之间的运算定义在哪里?我也想看看。
【在 T*****9 的大作中提到】 : unsigned int 0最小
|
t****t 发帖数: 6806 | 4 9 Many binary operators that expect operands of arithmetic or enumera-
tion type cause conversions and yield result types in a similar way.
The purpose is to yield a common type, which is also the type of the
result. This pattern is called the usual arithmetic conversions,
which are defined as follows:
--If either operand is of type long double, the other shall be con-
verted to long double.
--Otherwise, if either operand is double, the other shall be converted
【在 k*****l 的大作中提到】 : 回答的真含蓄 :) : 这种不同类型之间的运算定义在哪里?我也想看看。
|
T*****9 发帖数: 2484 | 5 thrust大牛
你这个文档是啥?能告诉我么?
【在 t****t 的大作中提到】 : 9 Many binary operators that expect operands of arithmetic or enumera- : tion type cause conversions and yield result types in a similar way. : The purpose is to yield a common type, which is also the type of the : result. This pattern is called the usual arithmetic conversions, : which are defined as follows: : --If either operand is of type long double, the other shall be con- : verted to long double. : --Otherwise, if either operand is double, the other shall be converted :
|
t****t 发帖数: 6806 | 6 this is the approximation of c++98 standard (97/11 draft)
【在 T*****9 的大作中提到】 : thrust大牛 : 你这个文档是啥?能告诉我么?
|
T*****9 发帖数: 2484 | 7 thx!
【在 t****t 的大作中提到】 : this is the approximation of c++98 standard (97/11 draft)
|
t*****h 发帖数: 137 | 8 And also the usual arithmetic conversions covered in Arithmetic Conversions
are applied to operands of arithmetic types in relational operators.
This is really a subtle issue which has me caught. |
l*****d 发帖数: 359 | 9 Conversion rules are more complicated when unsigned operands are involved.
The problem is that comparisons between signed and unsigned values are
machine-dependent, because they depend on the sizes of the various integer
types. For example, suppose that int is 16 bits and long is 32 bits. Then -
1L < 1U, because 1U, which is an unsigned int, is promoted to a signed long.
But -1L > 1UL because -1L is promoted to unsigned long and thus appears to
be a large positive number. |
t*****h 发帖数: 137 | |
t****t 发帖数: 6806 | |
l***g 发帖数: 1035 | 12 ansi standard, comparison between sized and unsized int is compiler depe
ndent, in other word, undefined.
【在 t*****h 的大作中提到】 : I have a following question about unsigned and int type, and the result : really surprised me. : ubuntu 8.04 and g++ 4.24 : Here is the code : #include : using namespace std; : int main() : { : unsigned x = 1; : int k = 1;
|
t*****g 发帖数: 12 | 13 nonono, compiler-dependent (i.e. implementation defined) is totally
different from undefined.
【在 l***g 的大作中提到】 : ansi standard, comparison between sized and unsized int is compiler depe : ndent, in other word, undefined.
|
b******g 发帖数: 54 | 14 就是,非常欠揍
【在 k*****l 的大作中提到】 : 回答的真含蓄 :) : 这种不同类型之间的运算定义在哪里?我也想看看。
|