iririri·7년 전·discussI'm pretty sure it's possible to get it to look like "choose { cases... } end;" instead, which is what I did in a mostly joke library I wrote to see how far I could go with the C preprocessor: chan_select(2) { chan_case_send(c, &foo, 0): do_stuff(); chan_case_recv(c, &bar, 1): do_other_stuff(bar); } chan_select_end; But the implementation (https://github.com/iriri/libcee/blob/master/include/cee/chan...) is both horrifying and not as efficient as just doing the sane thing: chan_case cases[] = { chan_case(c, CHAN_SEND, &foo), /* unfortunately still a macro but it's basically just a struct literal */ chan_case(c, CHAN_RECV, &bar), }; switch (chan_alt(cases, 2)) { case 0: do_stuff(); break; case 1: do_other_stuff(bar); }
But the implementation (https://github.com/iriri/libcee/blob/master/include/cee/chan...) is both horrifying and not as efficient as just doing the sane thing: