Last active
December 16, 2015 07:39
-
-
Save felipecruz/5400502 to your computer and use it in GitHub Desktop.
C - switch/goto coroutine example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdint.h> | |
uint8_t next (uint8_t *data) { | |
static int running = 0; | |
static uint8_t *current; | |
switch (running) { | |
case 0: goto L0; | |
case 1: goto L1; | |
} | |
L0: | |
running = 1; | |
current = data; | |
while (current) { | |
printf("%c\n", *(current)); | |
current = (++current); | |
return *(current); | |
L1:; | |
} | |
} | |
int main () { | |
while(next("ITERATE UNTIL THE END") != '\0') {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment