Assign values and Judge values in a statement at the same time

Source: Internet
Author: User

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




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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.