How to do while (0) in Linux kernel using C language
Why do while (0? Because it is indeed wonderful, and the implementation in the Linux kernel is quite good, let's look at the relevant code in the kernel:
#define db_error(fmt, ...) \ do { \
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
Why does while (0) wonderful? Since it's really good, and it's pretty good to implement in the Linux kernel, let's look at the relevant code in the kernel:#define DB_ERROR (FMT, ...) do { fprintf (stderr, "(Error):"); fprintf (stderr, FMT, # #
Benefits of using do {} while (0) in macro definition (reprinted), dowhileBenefits of using do {} while (0) in macro definition
#define MACRO_NAME(para) do{macro content}while(0)The following reasons are summarized: 1. the empty macro definition
Why does while (0) wonderful? Because it's really good, and it's pretty good to implement in the Linux kernel, let's look at the relevant code in the kernel:#define DB_ERROR (FMT, ...) do { fprintf (stderr, "(Error):"); fprintf (stderr, FMT, #
Benefits of using Do{}while (0) in macro definitions#define MACRO_NAME (para) Do{macro content}while (0)Format, summed up the following reasons: 1, empty macro definition to avoid warning: #define FOO () do{}while (0) 2, there is a separate block,
Benefits of using do {} while (0) in macro definition
#define MACRO_NAME(para) do{macro content}while(0)The following reasons are summarized: 1. the empty macro definition avoids warning: # define foo () do {} while (0) 2. An independent block
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,
# Define macro_name (para) do {macro content} while (0)The following reasons are summarized: 1. the empty macro definition avoids warning: # define Foo () do {} while (0) 2. An independent block exists, it can be used to define variables for
Day 4: loop structure (while, do... While, ),... While1. Loop Structure (while, do... While,)
1.1. What is a loop structure
In daily life, there will be a lot of things that need to be done repeatedly, such as four seasons of every year, 7 days of
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.