Macros using do{}while(0);

Posted by on mai 04, 2007
Fără categorie

If you ever had the chance to look in the Linux kernel sources, you might have seen macros defined like this:

#define foo(params) \
do{ \
//instructions \
}while(0)

This basicly means that the code is executed exactly once, so the first idea is that do{}while(0); is useless.
In fact, there are a number of reasons for writing the macros this way:

You can find more informations about this in the Kernelnewbies FAQ.

3 Comments to Macros using do{}while(0);

Lasă un răspuns

Adresa ta de email nu va fi publicată. Câmpurile obligatorii sunt marcate cu *

Acest site folosește Akismet pentru a reduce spamul. Află cum sunt procesate datele comentariilor tale.