Linux Help
guides forums blogs
Home Desktops Distributions ISO Images Logos Newbies Reviews Software Support & Resources Linuxhelp Wiki

Welcome Guest ( Log In | Register )



Advanced DNS Management
New ZoneEdit. New Managment.

FREE DNS Is Back

Sign Up Now
> Usage Of Do{ }while(0)
vasanth
post Mar 8 2005, 04:18 AM
Post #1


Whats this Lie-nix Thing?
*

Group: Members
Posts: 6
Joined: 26-February 05
Member No.: 4,701



Hello,
In the linux source code,we can see code which are enclosed by do{ statements; }while(0) .what is the use of this construct? will it not work without this do ..while construct.
Go to the top of the page
 
+Quote Post
 
Start new topic
Replies
imransadat
post Mar 30 2005, 10:20 AM
Post #2


Whats this Lie-nix Thing?
*

Group: Members
Posts: 1
Joined: 30-March 05
Member No.: 4,805



The do { } while(0) enclosure helps in making the group of statements in the macro into a single statement. e.g.

#define FOO(x) { function1(x); function(2); }
.
.
.

if (cond)
FOO(1);
else
FOO(2);

it will fail cause of the extra semi colon at the end. Also the do { } while(0) statement gives the macro the additional break statement which otherwise would need complex if else to implement.

try this page for more help http://c2.com/cgi/wiki?TrivialDoWhileLoop

Imran Sadat.
Go to the top of the page
 
+Quote Post

Posts in this topic


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 20th October 2017 - 01:04 PM