4 ms·
One of the links on the post, links to a stack overflow question, that has this code. What is the purpose of the do-while loop with the condition 0, how is that
by rdc12 12y ago
One of the links on the post, links to a stack overflow question, that has this code. What is the purpose of the do-while loop with the condition 0, how is that different to not having the loop at all?
#define BN_CONSTTIME_SWAP(ind) \
do { \
t = (a->d[ind] ^ b->d[ind]) & condition; \
a->d[ind] ^= t; \
b->d[ind] ^= t; \
} while (0)
- stephencanon 12y agoIt's a common C macro idiom, that makes a multi-statment macro behave like a single statement. See http://stackoverflow.com/questions/154136/do-while-and-if-else-statements-in-c-c-macros http://stackoverflow.com/questions/154136/do-while-and-if-el...
- bmm6o 12y agodo with a while (0) executes the body one time. This trick is used to package several statements into one, so it can be used in places like: if (foo) BN_CONSTTIME_SWAP(0);