Skip to content

Instantly share code, notes, and snippets.

@felipecruz
Last active December 16, 2015 07:39
Show Gist options
  • Save felipecruz/5400502 to your computer and use it in GitHub Desktop.
Save felipecruz/5400502 to your computer and use it in GitHub Desktop.
C - switch/goto coroutine example
#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