Home > Back-end >  Do {} While (); Special usage? !!!!! Exp expression take twice than what's the point?
Do {} While (); Special usage? !!!!! Exp expression take twice than what's the point?

Time:12-31

See such a piece of code in opencv

# define CV_Assert (expr) do {the if (!!!!! (expr)); Else CV: : error (CV: : error: : StsAssert, # expr, CV_Func, __FILE__ and __LINE__); } while (0)

1, why do you want to use the do {} while () to wrap the code? What's the use?
If it is in order to limit the scope, directly add {} do not?

2, if (!!!!! (expr)); This code what's the point? !!!!! Not equal to itself

Inside a lot of macro definition with judgment is like this, why?

CodePudding user response:

Bold code section is the same line, word wrap,,,,

CodePudding user response:

1.
Direct use of {} there will be such problem
If (exp)
CV_Assert (expr) ;
The else
.
Where else can't find the corresponding if
Use the do {} while (0), there is no this problem

2.!!!!! Exp is not equal to itself such as exp itself is 2!! Exp result is 1

CodePudding user response:

Do () while {0}; Role is to let you no matter how a SAO operation can be as a whole,

CodePudding user response:

See this post corresponding link below red fonts

CodePudding user response:

refer to the second floor lin5161678 response:
1.
Direct use of {} there will be such problem
If (exp)
CV_Assert (expr) ;
The else
.
Where else can't find the corresponding if
Use the do {} while (0), there is no this problem

2.!!!!! Exp is not equal to itself such as exp itself is 2!! Exp, the result is 1


First to understand, thank you

Second, understand take twice! The role of, is to keep any non-zero number into 1
But such a transformation sense, for the if non-zero is equivalent to 1, whether it is 2 and 4... And finally converted to 1 for judgment is no different

CodePudding user response:

reference 5 floor Chgooo reply:
first understand, thank you

Second, understand take twice! The role of, is to keep any non-zero number into 1
But such a transformation sense, for the if non-zero is equivalent to 1, whether it is 2 and 4... And finally converted to 1 for judgment is no difference of

Is no difference for the if
Wrote here just good-looking
If use in other places or useful
Such as 1 *!!!!! Exp expression
  • Related