Skip to content

Instantly share code, notes, and snippets.

@JAChapmanII
Created October 5, 2017 10:32
Show Gist options
  • Save JAChapmanII/b9806d47e9be9bc6f8ec7c6a20fdcc61 to your computer and use it in GitHub Desktop.
Save JAChapmanII/b9806d47e9be9bc6f8ec7c6a20fdcc61 to your computer and use it in GitHub Desktop.
loop comefrom
#include <stdio.h>
int main(int argc, char **argv) {
int i = 10;
comefrom loop;
if(i < 0) {
stop:;
}
printf("%d\n", i--);
loop:
comefrom stop;
printf("done\n");
return 0;
}
#!/usr/bin/bash
if [[ ! -f "$1" ]] || [[ -n "$2" ]]; then
echo "usage: $0 <file.cf>"
exit 0
fi
{
echo "// secret comefrom sauce"
echo "#define comefrom(x) x:"
echo "#define alabel(x) goto x;"
echo ""
sed -r \
-e 's/([^ \t]*):/alabel(\1);/' \
-e 's/comefrom ([^ ]*);/comefrom(\1);/' \
"$1"
} > out.c
gcc out.c
// secret comefrom sauce
#define comefrom(x) x:
#define alabel(x) goto x;
#include <stdio.h>
int main(int argc, char **argv) {
int i = 10;
comefrom(loop);
if(i < 0) {
alabel(stop);;
}
printf("%d\n", i--);
alabel(loop);
comefrom(stop);
printf("done\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment