[so] Auto-recursive main() function

Alexandru Goia goia at vivaldi.net
Mon Nov 12 07:48:39 EET 2018



October 07, 2018
Auto-recursive main() function
"Give me a place to stand and a lever long enough and I will move the 
world !" -- Archimedes

I prove that it is possible to write a recursive (auto-recursive) main() 
function, that is : we do not need to call another function from main() 
to recurse ourselves.

In the technicals of it, we must use both of the first 2 arguments of 
the main(argc, argv) function.

A external pointer must be used, so we can append to it some value that 
must be externalised.


  #include <stdio.h>

  int *addr;

  int main(int argc, char *argv[])
  {
   addr = & argc;
   ++(*addr);
   printf("Hello, world\n");
   return (argc < 10) ? main(argc, argv) : 0;
  }



PS : imi pot imagina si alte utilizari, precum _start() / 
_start_kernel() din Linux booting process,
punand la printk() ca argument un fisier .txt, obtinut dintr-o poza kewl 
(vezi Linux T-shirt, May the source be with you,
ori Christmas Tree .c/.txt in kernel, ori o poza cu o domnisoara draguta 
din vacanta de la mare ;-) , de preferinta prietena :-) ), poza trecuta
prin Jpeg2Ascii, aflat in Ubuntu, Debian si celelalte distributii, 
precum si pe Net ca packet independent. Amin.



---

https://romania-acknowledges-stars.blogspot.com        
https://ideas-of-creative-software.blogspot.com
https://alexandrugoia.yolasite.com                     
https://github.com/alexandergoia/kewl-source-code
                                    http://goia.go.ro/



More information about the so mailing list