(NULL == p) vs (p == NULL)
-
what different between (NULL == p) and (p == NULL) I realy confused about this, Any advise will be help.
If you accidentally write "=", but not "==" which you originally want it to be, then in the first case, compiler will tell you this mistake.But in the second case, compiler will not do this. This only prevent you to make mistakes, but I don't think this is necessary:)
-
If you accidentally write "=", but not "==" which you originally want it to be, then in the first case, compiler will tell you this mistake.But in the second case, compiler will not do this. This only prevent you to make mistakes, but I don't think this is necessary:)
Most newer compilers will give you a warning for doing an assignment operator in a conditional statement.
-
Most newer compilers will give you a warning for doing an assignment operator in a conditional statement.
I don't know which compliers you refer to, but when I test it with VS2005(which I am using now), it doesn't give any warning.Of course, here I'm using the default warning level: level 3. When I change it to Level 4, it indeed give a warning:)
-
I don't know which compliers you refer to, but when I test it with VS2005(which I am using now), it doesn't give any warning.Of course, here I'm using the default warning level: level 3. When I change it to Level 4, it indeed give a warning:)
You should always use level 4. There shouldn't be lesser levels.
-
what different between (NULL == p) and (p == NULL) I realy confused about this, Any advise will be help.
That's a pattern that is generally held to be rubbish nowadays. It only works when comparing an lvalue with an rvalue, and if you can remember to do it then you can remember to use the intended operator.
-
what different between (NULL == p) and (p == NULL) I realy confused about this, Any advise will be help.
I've always viewed the difference as purely cosmetic or "style" of the coder. Personally, I've always disliked the (NULL == p) style because when I look at code for debugging, my brain processes left to right so I want to read "if p is NULL".
-
what different between (NULL == p) and (p == NULL) I realy confused about this, Any advise will be help.
There is no difference between (NULL == p) or (p == NULL) Both are same. Actually it always better to prefer ( NULL == p ) Why because, To aviod the accident of assignment that can happen. say you are writing a statement (p == NULL ), but accidentally you wrote as p = NULL then the whole meaning is changed. But if you use ( NULL == p ) then forgetting to give NULL = p will give compiler error. From early days of programming this was a common error, so it now a standard to use as (NULL == p), which applicable to all the constants. It is always better to write constants on right side.
Величие не Бога может быть недооценена.