Subject: A Recursive main() Function

From: Shlomi Fish <[email-masked]>
Date: Fri, 1 Mar 2002 09:16:48 +0200 (IST)

Did anybody encounter a C program with a recursive (or indirectly
recursive) main function?

I think the C language allows for such a trick, because the compiler
bootstraps the process, and then makes a regular function call to main()
from the process initialization code.

It would be considered a very bad C-style but it seems like a very nice
trick. What if I called main() from somewhere to re-configure the program
using "command-line" parameters?

Regards,

	Shlomi Fish

There is no IGLU Cabal! After penetrating God's firewall (refer to OmerZ's
previous bit), they were able to spawn another instance of this reality.
Eventually, the IGLU Cabalists in the spawned reality spawned another
instance of reality there. And so forth to infinity. (there are also
rumours that two instances of reality were spawned in the "original"
reality...)

----------------------------------------------------------------------
Shlomi Fish        [email-masked]
Home Page:         http://t2.technion.ac.il/~shlomif/
Home E-mail:       [email-masked]

"Let's suppose you have a table with 2^n cups..."
"Wait a second - is n a natural number?"

---

From: Shlomi Fish <[email-masked]>
Date: Fri, 1 Mar 2002 09:27:13 +0200 (IST)

> rumours that two instances of reality were spawned in the "original"

Correct me if I'm wrong, but I think this is our first "There is no IGLU
Cabal" sequel. So, I'm patenting the practice of TINIC sequels under
U.S. patent No. 6.02214199 * 10^23. Party at my place to celebrate the
occasion.

	Shlomi Fish

There is no IGLU Cabal! There is no IGLU Cabal - The Next Generation.
There is no IGLU Cabal - the early years. There is no IGLU Cabal
3.1415926535 - The most irrational story. There is no IGLU Cabal - The
Redundant Sequel. There is no IGLU Cabal - ...

> To unsubscribe from this group, send an email to:
> [email-masked]
>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>

---

From: mulix <[email-masked]>
Date: Fri, 1 Mar 2002 10:54:20 +0200

> recursive) main function?

that would be considered god-awful c style. 

> from the process initialization code.

indeed, as far as i know. . 

> using "command-line" parameters?

then your design is borked. in any non trivial program, main is simply
the driver, doing something which ranges between:

do_thing(); 

to 

do_thing1();
do_thing2(); 
do_thing3(); 
...
do_thingn(); 

i.e., if you need to reconfigure your program, allow for it and call
the necessary do_configure() or whatever. 

btw, calling main() recursively works fine:

#include <stdio.h>

int main(int ac, char** av)
{
	printf("ac is %d\n", ac); 
	if (ac < 10)
		main(++ac, NULL); 
	return ac; 
}

-- 
The ill-formed Orange		
Fails to satisfy the eye:       http://vipe.technion.ac.il/~mulix/ 
Segmentation fault.		http://syscalltrack.sf.net/

---

From: Omer Zak <[email-masked]>
Date: Fri, 1 Mar 2002 11:33:39 +0200 (EET)

> Redundant Sequel. There is no IGLU Cabal - ...

                                             --- Omer
There is no IGLU Cabal.  Shlomi Fish has obtained a patent on certain key
technologies essential for existence of IGLU Cabals.  He is available for
license negotiations only on February 29th of odd-numbered years, between
the hours 14:15:09-18:28:18.
People, who practice IGLU Cabalism without the appropriate patent
licenses, risk teleportation into the interior of exploding supernovae.
WARNING TO SPAMMERS:  at http://www.zak.co.il/spamwarning.html

---

From: Oleg Goldshmidt <[email-masked]>
Date: 02 Mar 2002 19:05:48 -0500

> recursive) main function?

Indirectly? Write a shell script that invokes some other tool. Both
the shell and the tool have main(), don't they?

> I think the C language allows for such a trick, 

main() is just a function - there is nothing really special about it.

> trick. 

It's not just a very bad C style. It's bad programming. The purpose of
main() is to get the environemnt, get the command-line arguments, and
maybe handle the globals. You shouldn't bloat main with much else.

-- 
Oleg Goldshmidt | [email-masked] 
If it aint't broken it hasn't got enough features yet.