11 ms·
Enjoyed this article, anybody know the significance of adding the do..while(0) loop within the macro starting Linux 1.3? Was curious if it guards against some
by filereaper 8y ago
Enjoyed this article, anybody know the significance of adding the do..while(0) loop within the macro starting Linux 1.3?
Was curious if it guards against some C pre-processor issues.
/** include/asm-i386/system.h */
#define switch_to(tsk) do {
[...]
} while (0)
- akuma73 8y agoGood answer here: https://stackoverflow.com/questions/257418/do-while-0-what-is-it-good-for https://stackoverflow.com/questions/257418/do-while-0-what-i...
- berti 8y agoJust to add more context, this is a very common cpp (c pre-processor) idiom. You'll find it in most non-trivial C projects somewhere.
- pantalaimon 8y agoAbbreviating the C Preprocessor as cpp is very confusing imho.
- Someone 8y agoIt enables you to invoke the macro as if it were an expression statement consisting of a function call, regardless of where it appears. For details, see http://c-faq.com/cpp/multistmt.html http://c-faq.com/cpp/multistmt.html:
- loeg 8y agoIn particular, a single statement. I'm sure the link covers it, but: if (foo) MULTI_LINE_MACRO; Breaks without some wrapper like if (1) { A; B; } or do { A; B; } while (0): if (foo) A; B; // oops, unconditional (e.g., "goto fail")