Truth
03-25-2012, 11:20 PM
if (NULL == vertex->right() == vertex->left())
// wutdo
Seems legit, if both values equal NULL, we wutdo.
THAT IS UNTIL we take apart and realize how the compiler sees this statement differently from us. NULL is #define'd as 0. Boolean values are represented by 1 = true, 0 = false
So if the right vertex was NULL, it would evaluate that part of the equation to True before moving on. Now we would basically have the following:
if (1 == vertex->left())
Not what we want at all.
Likewise, if vertex->right() was not NULL, it would evaluate to false. So now we have:
if (0 == vertex->left()
This is also wrong, since right had a value.
Correct:
if (vertex->right() == NULL && vertext->left() == NULL)
http://www.pc-xp.com/wp-content/uploads/2010/12/bug_no_400.png
// wutdo
Seems legit, if both values equal NULL, we wutdo.
THAT IS UNTIL we take apart and realize how the compiler sees this statement differently from us. NULL is #define'd as 0. Boolean values are represented by 1 = true, 0 = false
So if the right vertex was NULL, it would evaluate that part of the equation to True before moving on. Now we would basically have the following:
if (1 == vertex->left())
Not what we want at all.
Likewise, if vertex->right() was not NULL, it would evaluate to false. So now we have:
if (0 == vertex->left()
This is also wrong, since right had a value.
Correct:
if (vertex->right() == NULL && vertext->left() == NULL)
http://www.pc-xp.com/wp-content/uploads/2010/12/bug_no_400.png