Un naufragio personal

Ángel Ortega

How to Get Fired Using Switch Statements and Statement Expressions

An orchard of batshit insane things done using the switch C keyword. For example, co-routines:

#include 

#define coroutine_begin() static int state=0; switch(state) { case 0:
#define coroutine_return(x) { state=__LINE__; return x; case __LINE__:; }
#define coroutine_finish() }

int get_next(void) {
        static int i = 0;
        coroutine_begin();
        while (1){
                coroutine_return(++i);
                coroutine_return(100);
        }
        coroutine_finish();
}

int main(void){
        printf("i is %d\n", get_next()); /*  Prints 'i is 1' */
        printf("i is %d\n", get_next()); /*  Prints 'i is 100' */
        printf("i is %d\n", get_next()); /*  Prints 'i is 2' */
        printf("i is %d\n", get_next()); /*  Prints 'i is 100' */
        return 0;
}

https://blog.robertelder.org/switch-statements-statement-expressions/