Linked Questions

457 votes
5 answers
218k views

I've been seeing that expression for over 10 years now. I've been trying to think what it's good for. Since I see it mostly in #defines, I assume it's good for inner scope variable declaration and for ...
gilm's user avatar
  • 8,110
242 votes
1 answer
155k views

Possible Duplicates: What’s the use of do while(0) when we define a macro? Why are there sometimes meaningless do/while and if/else statements in C/C++ macros? do { … } while (0) ...
krasnaya's user avatar
  • 3,165
151 votes
2 answers
66k views

Possible Duplicates: Do-While and if-else statements in C/C++ macros do { ... } while (0) — what is it good for? I'm reading the linux kernel and I found many macros like this: #define ...
amazingjxq's user avatar
  • 4,747
45 votes
7 answers
25k views

Possible Duplicate: Why use apparently meaningless do-while and if-else statements in macros? Why is the do while(false) necessary in the macros below? #define LOG(message, ...) \ do { \ Lock<...
sivabudh's user avatar
  • 32.7k
26 votes
6 answers
9k views

Possible Duplicates: What’s the use of do while(0) when we define a macro? Why are there sometimes meaningless do/while and if/else statements in C/C++ macros? C multi-line macro: do/...
grokus's user avatar
  • 19.4k
29 votes
3 answers
26k views

Possible Duplicate: Why are there sometimes meaningless do/while and if/else statements in C/C++ macros? I met code like below: #define ev_io_init(ev,cb,fd,events) \ do { \ ev_init ((ev), (cb));...
ciphor's user avatar
  • 8,318
13 votes
4 answers
11k views

Possible Duplicates: Why are there sometimes meaningless do/while and if/else statements in C/C++ macros? do { … } while (0) what is it good for? I'm working on some C code filled with ...
igul222's user avatar
  • 8,657
5 votes
5 answers
3k views

Possible Duplicate: Why are there sometimes meaningless do/while and if/else statements in C/C++ macros? When one needs to execute multiple statements within preprocessor macro, it's usually ...
aland's user avatar
  • 5,309
7 votes
3 answers
5k views

Possible Duplicate: Do-While and if-else statements in C/C++ macros gcc (GCC) 4.7.2 c89 Hello, I have the following function-like macro and just wondering what is the preferred usage when using ...
ant2009's user avatar
  • 22.7k
6 votes
3 answers
1k views

As a C newbie I'm having trouble understanding the following code: #define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \ } while (0) I gathered that the reason ...
l0b0's user avatar
  • 59.6k
1 vote
3 answers
2k views

Lately, I see more and more code pieces that use the template of: do { ... some code ... } while (false); Why to do this? If I'm not mistaken, the code will run only one time so the loop is seem ...
Reflection's user avatar
  • 2,116
1 vote
2 answers
1k views

I have noticed a programming style in Embedded C, used for firmware programming: #define WRITE_REGISTER(reg, value) \ do { \ write_to_register(reg, value); \ } while (0) ...
2 votes
2 answers
473 views

I recently saw a piece of C code including a macro of the following style: #define TOTO() \ do { \ do_something(); \ do_another_something(); \ } ...
Aracthor's user avatar
  • 5,957
3 votes
3 answers
987 views

What is the significance of do while loop when the condition inside the while loop is 0 i.e. always false. do { //some code implementation. }while(0); I have seen at many places this is being used. ...
Aragon's user avatar
  • 1,551
1 vote
2 answers
2k views

Is it correct way to write a multiple statements in one Macro? #define AB() do { printf("hi"); } while(0)
msc's user avatar
  • 35.1k

15 30 50 per page
1
2 3 4 5
...
11