Browsing all articles tagged with encapsulation with macro - Share Programming Tips
Feb
26

What’s the need of using encapsulation { do..while(0) block } in define a macro in C programming?

While reading many codes in c programming based open source project i came to know one interesting things. Let me explain you by some sample code.

#define Assert(v)   if(!(v)) printf("Error occurred at: %s, in %s at %i",  #v, __FILE__, __LINE__);

At most of the experienced people used to write such macro in following style

 #define Assert(v)   do { if(!(v)) printf("Error occurred at: %s, in %s at %i",  #v, __FILE__, __LINE__); } while(0)

This method is called as making encapsulating our macro.

Now let me explain you whats the need of this….

read more

Follow us on Twitter! Follow us on Twitter!

Search in this website

our sponsors

latest comments

Find us on Facebook

Top Authors

35 posts
saurabh
22 posts
10 posts

Find us on stackoverflow

Polls

Tell us who you are

View Results

Loading ... Loading ...

My Bookmarks

Sponsers Link