From 08f75cf88252a3a95ee8eb8464295bcd177ec74f Mon Sep 17 00:00:00 2001 From: Tyge Lovset Date: Wed, 21 Jun 2023 09:11:49 +0200 Subject: Fixed cco_switch: emulation of switch inside coroutines. --- include/stc/algo/coroutine.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/stc/algo/coroutine.h b/include/stc/algo/coroutine.h index a2496d25..e0cf5488 100644 --- a/include/stc/algo/coroutine.h +++ b/include/stc/algo/coroutine.h @@ -66,9 +66,9 @@ enum { #define cco_initial(co) ((co)->cco_state == 0) #define cco_done(co) ((co)->cco_state == cco_state_done) -/* Always use { } after cco_switch(x), cco_case(val), and cco_default. */ -#define cco_switch(x) for (intmax_t _sw = (intmax_t)(x), _once=1; _once; _once=0) -#define cco_case(val) if (_sw == (intmax_t)(val)) +/* Emulate switch in coro: always use { } after cco_case(val) and cco_default. */ +#define cco_switch(x) for (long long _sw = (long long)(x), _b=0; !_b; _b=1) +#define cco_case(val) if (_b |= _sw == (val)) #define cco_default #define cco_routine(co) \ -- cgit v1.2.3