Why are there so many do {} while (0) Macros in the kernel? I don't understand it at first. It doesn't seem to work. But after understanding it, you will know its benefits. The benefit lies in the macros of multiple statements.
# Define Foo (x)
Author: cpoint Source: http://www.cnblogs.com/cpoint/
In the Linux kernel code, often see Do...while (0) of the macro, Do...while (0) has a lot of effect, the following list of several: 1, avoid goto statement:
Typically, if a function starts to
Use goto elegance and avoid structural confusionThe statement you want to jump to with do{...} while (0) you can wrap it up.Reference #defien N BOOLExecute () {//Allocate resources int*p = (int*)mallocNsizeof(int));BOOLBOk =true;//Run and error
Read the Linux source when you see a bunch of these macro:#define FOO (x) does {f (x); g (x);} while (0)I've been trying not to understand why not use it directly#define FOO (x) f (x); g (x);Or:#define FOO (x) {f (x); g (x);}Search for a moment to
The clever use of do... while (0) in C language-avoid goto
Use goto elegance and avoid structure confusionUse do {…} to jump to the statement {...} Pack while (0.Reference
# Defien N 10 bool Execute () {// allocate resource int * p = (int *) malloc (
In the Linux KernelCodeHas such macro definition:# Define dump_write (ADDR, NR) do {memcpy (bufp, ADDR, NR); bufg + = nR;} while (0)
This macro definition means that the loop body will be executed once when this macro operation is referenced, but
For example, define macro, # define free1 (p) if (p) Free (P)Then, call:If (expression)Free1 (P );ElsePrintf ("expression was false. \ n ");Expand:If (expression)If (p) Free (P );ElsePrintf ("expression was false. \ n ");Let's see if else matches
Requirement: When the font is displayed on the screen, if there are too many characters to be displayed by branch (divided into two lines), the first line and the second line each account for half of the characters.
Because the displayed string is
1. do {} while (0) in the source code)
Write a code today:
if(!CCScene::init()){return false;}Later I went to the source code:
bool CCScene::init(){ bool bRet = false; do { CCDirector * pDirector; CC_BREAK_IF( !
Akagi201 code style
1. application code and driver kernel code styles should be consistent as much as possible
2. The project directory name and file name can be underlined in lower case, without-connection, because the variable name in the source
From some classic
Code Is often seen in the macro
Do... while (0) Usage, feeling
Do... while (0) It is replaced only when it is possible to jump out of a subsequent code section.
Goto In other ways, the rest will not solve the problem.
I
File: vgaspeed.txtName: test the speed of the vga12h ModeAuthor: zyl910Blog: http://blog.csdn.net/zyl910/Version: V1.0Updata: 2006-11-14
Download (note the modified extension)
Introduction~~~~I 've written a lot of screen writing code in DOS, but I
The ACE source code OS _memory.h is defined in this way.
# if defined (ACE_HAS_NEW_NOTHROW)# define ACE_NEW_RETURN(POINTER,CONSTRUCTOR,RET_VAL) \ do { POINTER = new (ACE_nothrow) CONSTRUCTOR; \ if (POINTER == 0) { errno = ENOMEM; return
In C ++, there are three types of loop statements: For, while, and do... while, but in general applications for loop, we may use for and while to have more, do... while is relatively not valued.HoweverCodeBut I found some clever usage of do... while,
Under Linux, you can use some macros, plus custom format output, to make the output easier to debug:Typesetting may be a bit messy, note do{}while (0); it's in one line.[CPP]View PlainCopy
#include
#include
#define DEBUG1 (FMT, arg ...)
Every time I write a summary, I think it is a headache, because I know that the summary is really important, and it almost directly determines the number of readers. It may take a lot of effort to write things, because the failure of the abstract
In-depth understanding of php kernel 1. I have a deep understanding of the php kernel and read the explanations used by 1do {} while (0). do {} while (0) is mainly used for the robustness and versatility of basic functions, and flexible use of some
In the Linux kernel (linux-4.14.12/mm/slab.c#3389), at first glance at the bottom of the code, it seems that L3389 have a bug, so I read around the interest of a bit local_irq_save/local_irq_ The source code of the restore./*linux-4.14.12/mm/slab.c#3
Article Title: synchronization and mutex Analysis Report in the kernel. Linux is a technology channel of the IT lab in China. Including desktop applications, Linux system management, kernel research, embedded systems, open source, and other basic
I. Basic data types:
The data type can be understood as an alias with a fixed memory size. It is a model for creating variables.
A variable is an alias for an actual Continuous Bucket. In a program, you can apply for and name a bucket through a
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.