arch detail

arch detail
Showing posts with label silly. Show all posts
Showing posts with label silly. Show all posts

Friday, September 02, 2011

Crazy C program

I don't know why I love this, but you can actually call main() from inside a C program! Or at least, with GCC 4.4.3 will let you. I wonder if other compilers allow this?

#include 


int main(int argc, char** argv) {
if (argc == 0) {
return 0;
}
else {
printf("%s\n", argv[0]);
main(argc - 1, &(argv[1]));
}
}


Compile it and try:

$ ./a.out a b c d

./a.out
a
b
c
d