What is the point of a do { ... } while (false); construct? for example: do { \ UWtype __clz__b, __clz__c, __clz__x = (x); \ ALPHA_CMPBGE_0 (__clz__b, __clz__x); /* zero bytes */ \ __clz__b = __clz_tab [(__clz__b >> 1) ^ 0x7F]; /* 8 to 1 byte */ \ __clz__b = __clz__b * 8 - 7; /* 57 to 1 shift */ \ __clz__x >>= __clz__b; \ __clz__c = __clz_tab [__clz__x]; /* 8 to 1 bit */ \ __cl
do { \ UWtype __clz__b, __clz__c, __clz__x = (x); \ ALPHA_CMPBGE_0 (__clz__b, __clz__x); /* zero bytes */ \ __clz__b = __clz_tab [(__clz__b >> 1) ^ 0x7F]; /* 8 to 1 byte */ \ __clz__b = __clz__b * 8 - 7; /* 57 to 1 shift */ \ __clz__x >>= __clz__b; \ __clz__c = __clz_tab [__clz__x]; /* 8 to 1 bit */ \ __clz__b = 65 - __clz__b; \ (count) = __clz__b - __clz__c; \ } while (0)
I know that it is possible to break; out of a do {...} while loop, but in that case why not just use a goto? I guess it's more structured using the do loop :-P
you can also continue in a do { } while (false); loop :-P unlike gotos
do garuntees that the code runs 1 time and while repeats it but if while cannot proceed the code still has run 1 time.
This is useful and I recently learned it and I have a plan for it :)
do does indeed run at least once, but what is the point of using it anyway if you write a condition that is always false?
Well, goto is less structured in that it can literally jump you anywhere in the code. That makes while a little “safer”, in that you won't accidentally move something around and get behavior where you jump into the middle of another function.
Join our real-time social learning platform and learn together with your friends!