Created
October 5, 2017 10:32
-
-
Save JAChapmanII/b9806d47e9be9bc6f8ec7c6a20fdcc61 to your computer and use it in GitHub Desktop.
loop comefrom
This file contains hidden or 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 <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; | |
} |
This file contains hidden or 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
#!/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 |
This file contains hidden or 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
// 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