4 ms·
Can you explain what you meant by that? (Today, that code might be done with inline functions but that wasn't an option back then)
by Simon_Fe 5y ago
Can you explain what you meant by that?
(Today, that code might be done with inline functions but that wasn't an option back then)
- marcodiego 5y agoSuppose we do #define multiline insns1;\ insns2; and then, on my code I use: if(cond) multiline; then insns2 will be executed regardless of cond. Even if we do #define multiline {\ insns1;\ insns2;\ } then, if we use if(cond) multiline; else other; will give us a syntax error before "else". The usual way to make multiline defines work correctly for any case is: #define multiline do {\ insns1;\ insns2;\ }while(0) This will force the programmer to add ';' after using it and it won't break. This is used in many high-profile projects including the linux kernel.
- Simon_Fe 5y agoFair enough. I've certainly used that in other code (eg wrappers around mallocs with checks etc) but this was specifically for that ".c" file so it didn't really matter. (Also, not sure we could assume the code optimisation was all that great on the compilers back then :-) )