This "choose {" "end }" business is an awful way to design the macro. If you need nesting that involves a block, with prolog and epilog material on either or both ends, you just have to hide that into the macro:
selbegin;
out(ch, int, 42):
foo();
in(ch, int, i):
bar(i);
otherwise:
baz();
selend;
I don't understand the downvotes. I have 30 years of (continous!) C experience. This is the best practice for doing a macro like this.This "end }" business has improper nesting, visually. The choose is outside of the braces, the end is within; it is scatter-brained. There is no error checking for a forgotten end.
I'm looking at the implementation and it's looking quite weird! choose simply expands into mill_choose_init__, and end expands into mill_choose_end__. The definitions of these seem as if they should pair together:
#define mill_choose_init__ \
{\
mill_choose_init_(MILL_HERE_);\
int mill_idx = -2;\
while(1) {\
if(mill_idx != -2) {\
if(0)
#define mill_choose_end__ \
break;\
}\
}\
mill_idx = mill_choose_wait_();\
}
But, oops, look at the obvious lack of balance in the braces. mill_choose_init__ {
mill_choose_end__ }
we are putting a brace after the if (0) which balances the one after break, and the final missing brace that balances the one opened internally in mill_choose_init__.There are best practices to design this sort of macrology that don't require the user put braces in weird places to balance the inconsistencies in macro expansions.
Speaking as a professional, I would not pass this in a code review.
That we have to use a flaky preprocessor in order to get a half decent syntax is already a significant regret. We must not compound the regret by allowing the macrology to be less than as good as it can be.