由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - does any one know the answer?
相关主题
C怪问题一个[合集] C++ function signature问题
C++11的lambda不会破坏可读性吗?c++ question
写code都推一起很牛逼吗最近revisited C++11,得出一个感慨。scala比c++还是简单多了
Two classic C++ questions, how to answer今天给c++震惊了
how to look the values in a vector in VC.NET容器中放置智能指针一问
what's the differencehow to debug mpi?
cannot trace var values in vs2005能否给些讲debug经验的文章和书籍 (转载)
New "KENG" about Perl.一个debug的问题
相关话题的讨论汇总
话题: max话题: value话题: answer话题: know话题: return
进入Programming版参与讨论
1 (共1页)
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;

1 (共1页)
进入Programming版参与讨论
相关主题
一个debug的问题how to look the values in a vector in VC.NET
不同compiler速度可以差很远吗?what's the difference
After build,how to run the program on visual C# 2008cannot trace var values in vs2005
问个超简单的C问题New "KENG" about Perl.
C怪问题一个[合集] C++ function signature问题
C++11的lambda不会破坏可读性吗?c++ question
写code都推一起很牛逼吗最近revisited C++11,得出一个感慨。scala比c++还是简单多了
Two classic C++ questions, how to answer今天给c++震惊了
相关话题的讨论汇总
话题: max话题: value话题: answer话题: know话题: return