Вопрос

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