Loading ...
Sorry, an error occurred while loading the content.

Re: [hackers-il] A Recursive main() Function

Expand Messages
  • mulix
    ... that would be considered god-awful c style. ... indeed, as far as i know. . ... then your design is borked. in any non trivial program, main is simply the
    Message 1 of 6 , Mar 1 12:54 AM
    • 0 Attachment
      On Fri, Mar 01, 2002 at 09:16:48AM +0200, Shlomi Fish wrote:
      >
      > Did anybody encounter a C program with a recursive (or indirectly
      > recursive) main function?

      that would be considered god-awful c style.

      > 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.

      indeed, as far as i know. .

      > 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?

      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/
    • Omer Zak
      ... 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
      Message 2 of 6 , Mar 1 1:33 AM
      • 0 Attachment
        On Fri, 1 Mar 2002, Shlomi Fish wrote:

        > 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 - ...

        --- 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
      • Oleg Goldshmidt
        ... Indirectly? Write a shell script that invokes some other tool. Both the shell and the tool have main(), don t they? ... main() is just a function - there
        Message 3 of 6 , Mar 2 4:05 PM
        • 0 Attachment
          Shlomi Fish <shlomif@...> writes:

          > Did anybody encounter a C program with a recursive (or indirectly
          > 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.

          > It would be considered a very bad C-style but it seems like a very nice
          > 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 | ogoldshmidt@...
          If it aint't broken it hasn't got enough features yet.
        • Arik Baratz
          Oh yes. I ve seen a few. Usually it s those cryptic programs that people used to put in their signature files. -- Arik ... From: Shlomi Fish
          Message 4 of 6 , Mar 3 12:40 AM
          • 0 Attachment
            Oh yes. I've seen a few. Usually it's those cryptic programs that people
            used to put in their signature files.

            -- Arik

            -----Original Message-----
            From: Shlomi Fish [mailto:shlomif@...]
            Sent: Friday, March 01, 2002 9:17 AM
            To: Hackers-IL
            Subject: [hackers-il] A Recursive main() Function



            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 shlomif@...
            Home Page: http://t2.technion.ac.il/~shlomif/
            Home E-mail: shlomif@...

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



            To unsubscribe from this group, send an email to:
            hackers-il-unsubscribe@egroups.com



            Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/



            **********************************************************************
            This email and any files transmitted were scanned by
            Port Authority Enterprise for unauthorized content.
            **********************************************************************
          Your message has been successfully submitted and would be delivered to recipients shortly.