Do {} while (0) interpretation in the Cocos2d-x

Source: Internet
Author: User

Do {} while (0) interpretation in the Cocos2d-x

 


This article for beginners of Cocos2d-x to explain do {} while (0) Usefulness!


Its significance lies in its ability to implement complicated definitions and versatility, which can be applied in any situation.


# Define CC_BREAK_IF (cond) if (cond) break

We use the CC_BREAK_IF macro definition as an example to summarize the following points:
(1) avoid empty macro definitions
For example, if: cond = NULL, it is: # define CC_BREAK_IF (NULL) if (NULL) break


(2) If the macro appears after the judgment statement, it can be implemented as a whole:


# Define lizi ()\
Fangfa1 ();\
Fangfa2 ();
In the following situation:
If (NULL = dJ)
Lizi ();


Fangfa1 () and fangfa2 () will not be executed at the same time, and this is obviously not the purpose of program design.
(3) when this occurs, why must I use the do {} while (0) statement?


Take a look at the following example:


# Define switch (x, y) {int temp; temp = x; x = y; y = temp ;}
If (x> y)
Switch (x, y );
Else // will cause an error, because the subsequent statement will be redundant.


Use do {} while (0) to include it and become an independent statement to avoid the above problems.


 

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: info-contact@alibabacloud.com 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.