Assign values and Judge values in a statement at the same time
I occasionally write fun articles. It should come from another source, but I am afraid of compatibility problems. // 2007.10.10 is incorrect. For details, see note
Lpvoid lpprocessbuf = NULL;
If (null = (lpprocessbuf = virtualallocex (................)))
{...................}
In this statement, virtualallocex returns the value to lpprocessbuf, and then determines whether lpprocessbuf is null.
Passed in the VC 2005 compiler.
// Errors described below
The uncertain compiler explains: If lpprocessbuf = virtualallocex (...) if the value is successfully assigned, the return value is compared with null. because lpprocessbuf = virtualallocex (...) the value is always assigned successfully, and true is always returned. like if (dwdata = NULL), true is always returned.
// Incorrect description
Note
2007.10.10
If the above error is added, there will be no compatibility issues. For expression A = B, the return value is the left value, that is,
Then if (a = B) is 1. A = B 2. judge whether a is 0 (true or false)
If (dwdata = NULL) always returns true. If it determines that dwdata is 0 (false), it will not enter the IF.