Possible Duplicate:
What is the difference between these (bCondition == NULL) and (NULL==bCondition)?

From this question it says "const object on left side of comparison" is some how "better" than doing otherwise. Why is this?

有帮助吗?

解决方案

Any decent compiler will warn you about assignment within a conditional expression, so that form isn't very relevant these days.

On another point "use unsigned for variables that are >= 0 // nice trick " I heard that using unsigned can be confusing and shouldn't use unless there's a reason. Does anyone agree or refute this?

Use unsigned when the value should be unsigned.

其他提示

This is to avoid the "=" versus "==" mistake. If you mean "==" but type "=" and the object on the LHS is constant, the compiler will complain. For example,

if ( 3 == x )

is preferred to

if ( x == 3 )

because if you type

if ( 3 = x )

then you'll get an error, but if you type

if ( x = 3 )

then you may get a bug!

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top