l*****d 发帖数: 359 | 1 Is there a difference between the "if" tests shown below? If so, explain why
one might be preferred over the other.
if (*p == MAX_VALUE)
return -1;
if (MAX_VALUE == *p)
return -1; |
T*******i 发帖数: 4992 | 2 本版的版主太懒了
应该编个月经问题faq
why
【在 l*****d 的大作中提到】 : Is there a difference between the "if" tests shown below? If so, explain why : one might be preferred over the other. : if (*p == MAX_VALUE) : return -1; : if (MAX_VALUE == *p) : return -1;
|
l*****d 发帖数: 359 | 3 is there a short answer?
【在 T*******i 的大作中提到】 : 本版的版主太懒了 : 应该编个月经问题faq : : why
|
T*******i 发帖数: 4992 | 4 MAX_VALUE不能作lvalue,compiler可以帮助programmer避免把==写成=
【在 l*****d 的大作中提到】 : is there a short answer?
|
l*****d 发帖数: 359 | 5 原来如此。但问题现在==没有写错啊。what a tricky one!
【在 T*******i 的大作中提到】 : MAX_VALUE不能作lvalue,compiler可以帮助programmer避免把==写成=
|
E*****7 发帖数: 128 | 6 if (MAX_VALUE == *p) 误写成 if (MAX_VALUE = *p)编译器会报错。MAX_VALUE不能作
lvalue。
if (*p == MAX_VALUE) 误写成 if (*p = MAX_VALUE)编译器不会报错。 |
c*****t 发帖数: 1879 | 7 Both are okay.
*p == MAX_VALUE is better for the long run since it is more intuitive
and more easily readable. Just need to pay attention (easily trainable
habbit) when writing ==. It is a fairly easy bug to discover even if
you make a mistake as well.
ease of reading > ease of debugging
why
【在 l*****d 的大作中提到】 : Is there a difference between the "if" tests shown below? If so, explain why : one might be preferred over the other. : if (*p == MAX_VALUE) : return -1; : if (MAX_VALUE == *p) : return -1;
|
l*****d 发帖数: 359 | 8 thanks! but now i dont' know which answer is correct...
【在 c*****t 的大作中提到】 : Both are okay. : *p == MAX_VALUE is better for the long run since it is more intuitive : and more easily readable. Just need to pay attention (easily trainable : habbit) when writing ==. It is a fairly easy bug to discover even if : you make a mistake as well. : ease of reading > ease of debugging : : why
|
y*******9 发帖数: 7 | 9 2nd is better
why
【在 l*****d 的大作中提到】 : Is there a difference between the "if" tests shown below? If so, explain why : one might be preferred over the other. : if (*p == MAX_VALUE) : return -1; : if (MAX_VALUE == *p) : return -1;
|