The Linux kernel and some other Open-source code often encounter code like this:
do{...}while (0)Such code is not a loop, do ... While on the surface there is no meaning here, then why use it?
In fact, do{...} while (0) is much more useful than
Reproduced from: C language in Do...while (0) of the magical, thanks for sharing.In the Linux kernel code, often see Do...while (0) of the macro, Do...while (0) has a lot of role, the following list of several:1. Avoid goto statements:Typically, if
In C + +, there are three types of loop statements: for, while, and Do...while, but in the general application loop, we may use for and while to more, do...while relatively less attention.
But when we read the code for our project recently, we found
Value of Do{}while (0) When macro definition (#define) in C languageRecently found in the code of the new company everywhere used do{...} while (0), Google a bit, found that stack overflow early on a lot of discussion, summed up the discussion,
Recently looking at ESP32 's IDF, there are some macro definitions that use the Do while (0) code that seems to be useless. Then I looked up the information and found that it was often used in Linux kernel code!Now get this thing sorted out.Why do
In C + +, there are three types of loop statements: for, while, and Do...while, but in the general application loop, we may use for and while to more, do...while relatively less attention.But I've found some of the smartest uses of do...while, not
In the Linux kernel, statements such as do {} while (0) are often seen. Many people start to wonder that do {} while (0) is meaningless, because it will only be executed once, the effect of adding do {} while (0) without adding do is exactly the
A popular saying on the Internet recently is: Yuan Fang. What do you think? So do {…} used in the macro definition in the Linux Kernel {...} While (0), Yuan Fang, what do you think?
If you know the truth, write a few lines of code for debugging.
Do {} while (0) can be seen in both the Linux kernel and other famous C and C ++ libraries)Such Writing seems meaningless. In fact, it comes from famous masters and is used in macro definition.Previously, I learned that using the semicolon after
Do {} while (0) is a perfect match with CC_BREAK_IF, whilecc_break_if
From the very beginning, I felt that it was unnecessary and very useful. I 've been using this structure for about two months. Let's summarize how to use this structure.
First
C ++ do while 0 usage and significance, dowhile
/* Usage and significance of do while 0 * // recently, do while 0 has been seen in many codes. At first glance, didn't this do anything? Why. Is that an alternative? Of course not. // 1.0 help
Why do I encounter many # defines... do {...} while (0) in the kernel )?
There are several reasons:
· Empty statements will be warned during compilation, so it is necessary to use # define Foo do {} while (0 ).
· This is done to define local
I have seen some programs or macros using do {} while (0). I think it's quite strange. I don't know why I wrote this, so I am Baidu...
I have a good post to share with you!Macro I met
#define LFW(x, y) do { x = websGetVar(wp, T(#y), T("")); } while(
Not for the loop while.1. Use the macro definition to ensure that the macro must be executed in the way you want.#define FOO (x) Start (x); end (x)if (flag)Foo (x);The result of extending laterif (flag)Start (x);End (x);If it is do{...} while (0),
I have seen some programs or macros using do {} while (0). I think it's quite strange. I don't know why I wrote this, so I am Baidu... I have a good post to share with you! Macro [cpp] # define LFW (x, y) do {x = websGetVar (wp, T (# y), T (""));}
In the Linux kernel code, we often see the do... while (0) Macro. do... while (0) has many functions. Below are a few examples:
URL: http://www.cnblogs.com/archimedes/p/do-while-0.html.1. Avoid the goto statement:
Generally, if a function needs to
Thank you for your enthusiastic reply yesterday. I look up at the night sky, and the stars are shining like the eyes of all of you. This makes me realize that not only can I share the results, but also can I share confusion and loneliness. (This is
Reprint address: http://www.spongeliu.com/415.html Linux kernel and some other open source code, often encounter such code:
Do{...} while (0)
This code is not a loop at a glance, do. While the surface is meaningless here,
It is recommended that programmers skip this article and view the original article directly.
You may see a do loop where the conditional expression is constant 0. it creates a loop that will only be executed once. this programming method can place
Recently see the C language project in the macro definition used Do...while (0), feel is a knowledge point, special to summarize.First look at this sentence:do{...} while (0) is the only constructor in C that allows you to define a macro that always
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.