Reason # %ld not to use void main()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mrdarrett@gmail.com

    Reason # %ld not to use void main()

    typedef struct{
    int i, j;
    } deStruct;

    deStruct main()
    {
    deStruct k;

    k.i = 0;
    k.j = 10;
    return k;
    }

    Crashes when running the compiled code. (I used the Borland C++ 5.5
    free command line tools)

    Spectacular, though.

    Michael
  • Martin Ambuhl

    #2
    Re: Reason # %ld not to use void main()

    mrdarrett@gmail .com wrote:
    typedef struct{
    int i, j;
    } deStruct;
    >
    deStruct main()
    ^^^^^^^^
    main returns an int. This is an obvious error.
    {
    deStruct k;
    >
    k.i = 0;
    k.j = 10;
    return k;
    main returns an int. This is an obvious error.
    }
    >
    Crashes when running the compiled code. (I used the Borland C++ 5.5
    free command line tools)
    main returns an int. Your code is obviously erroneous.

    Comment

    • mrdarrett@gmail.com

      #3
      Re: Reason # %ld not to use void main()

      On Jan 2, 2:55 pm, Martin Ambuhl <mamb...@earthl ink.netwrote:
      mrdarr...@gmail .com wrote:
      typedef struct{
      int i, j;
      } deStruct;
      >
      deStruct main()
      >
      ^^^^^^^^
      main returns an int. This is an obvious error.
      >
      {
      deStruct k;
      >
      k.i = 0;
      k.j = 10;
      return k;
      >
      main returns an int. This is an obvious error.
      >
      }
      >
      Crashes when running the compiled code. (I used the Borland C++ 5.5
      free command line tools)
      >
      main returns an int. Your code is obviously erroneous.

      Yes, absolutely, of course it does return an int. And yes my code
      does crash, as intended.

      I was pondering why "void main(void)" shouldn't work. So, I thought,
      if it's wrong to declare main as void, then it should be wrong to
      declare main as arbitrary. That's what the deStruct structure (pardon
      the pun) was intended to show. And crash it did...

      Michael

      Comment

      • Kenny McCormack

        #4
        Re: Reason # %ld not to use void main()

        In article <5u2j3mF1g4nuvU 1@mid.individua l.net>,
        Martin Ambuhl <mambuhl@earthl ink.netwrote:
        >mrdarrett@gmai l.com wrote:
        >typedef struct{
        > int i, j;
        >} deStruct;
        >>
        >deStruct main()
        ^^^^^^^^
        main returns an int. This is an obvious error (no sh*t, Sherlock...).
        Marty is a serious head case, with no concept of a sense of humor.
        ....
        Marty is a serious head case, with no concept of a sense of humor.
        ....
        Marty is a serious head case, with no concept of a sense of humor.

        Comment

        • Martin Ambuhl

          #5
          Re: Reason # %ld not to use void main()

          mrdarrett@gmail .com wrote:
          I was pondering why "void main(void)" shouldn't work.
          Then you should have mentioned it in the body of your message.
          If something is important enough to be your main concern, it should be
          in the body of your message instead of the subject header, which tends
          to be useless except for identifying threads.

          Comment

          • andreyvul

            #6
            Re: Reason # %ld not to use void main()

            On Jan 2, 6:04 pm, mrdarr...@gmail .com wrote:
            Yes, absolutely, of course it does return an int. And yes my code
            does crash, as intended.
            >
            I was pondering why "void main(void)" shouldn't work. So, I thought,
            if it's wrong to declare main as void, then it should be wrong to
            declare main as arbitrary. That's what the deStruct structure (pardon
            the pun) was intended to show. And crash it did...
            >
            What compiler/machine are you using?
            It compiles and runs without error on gcc-mingw and msvc 2005 on
            windows xp sp2/i386.

            However, gcc-mingw DOES warn about main returning non-int.

            Comment

            • mrdarrett@gmail.com

              #7
              Re: Reason # %ld not to use void main()

              On Jan 2, 6:54 pm, andreyvul <andrey....@gma il.comwrote:
              On Jan 2, 6:04 pm, mrdarr...@gmail .com wrote:
              >
              Yes, absolutely, of course it does return an int. And yes my code
              does crash, as intended.
              >
              I was pondering why "void main(void)" shouldn't work. So, I thought,
              if it's wrong to declare main as void, then it should be wrong to
              declare main as arbitrary. That's what the deStruct structure (pardon
              the pun) was intended to show. And crash it did...
              >
              What compiler/machine are you using?
              It compiles and runs without error on gcc-mingw and msvc 2005 on
              windows xp sp2/i386.
              >
              However, gcc-mingw DOES warn about main returning non-int.

              I'm using the Borland C++ 5.5 free command line compiler.

              I get a window popping up on XP... forgot the exact error. When I
              return to work I can post it if you like...

              Michael

              Comment

              • Richard Heathfield

                #8
                Re: Reason # %ld not to use void main()

                mrdarrett@gmail .com said:
                typedef struct{
                int i, j;
                } deStruct;
                >
                deStruct main()
                {
                deStruct k;
                >
                k.i = 0;
                k.j = 10;
                return k;
                }
                >
                Crashes when running the compiled code. (I used the Borland C++ 5.5
                free command line tools)
                >
                Spectacular, though.
                >
                Yeah, I crashed NT4 once with double main, in much the same spirit of
                enquiry. I was rewarded with lots of blinkenlights. (A text screen
                appeared, randomly filled, and the flash attribute bit was set on a good
                many of the character positions.)

                --
                Richard Heathfield <http://www.cpax.org.uk >
                Email: -http://www. +rjh@
                Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
                "Usenet is a strange place" - dmr 29 July 1999

                Comment

                • mrdarrett@gmail.com

                  #9
                  Re: Reason # %ld not to use void main()

                  On Jan 2, 11:57 pm, Richard Heathfield <r...@see.sig.i nvalidwrote:
                  mrdarr...@gmail .com said:
                  >
                  >
                  >
                  typedef struct{
                  int i, j;
                  } deStruct;
                  >
                  deStruct main()
                  {
                  deStruct k;
                  >
                  k.i = 0;
                  k.j = 10;
                  return k;
                  }
                  >
                  Crashes when running the compiled code. (I used the Borland C++ 5.5
                  free command line tools)
                  >
                  Spectacular, though.
                  >
                  Yeah, I crashed NT4 once with double main, in much the same spirit of
                  enquiry. I was rewarded with lots of blinkenlights. (A text screen
                  appeared, randomly filled, and the flash attribute bit was set on a good
                  many of the character positions.)
                  >
                  --
                  Richard Heathfield <http://www.cpax.org.uk >
                  Email: -http://www. +rjh@
                  Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
                  "Usenet is a strange place" - dmr 29 July 1999

                  Wow, a double main! I'll have to try that sometime...

                  Michael

                  Comment

                  • Kenneth Brody

                    #10
                    Re: Reason # %ld not to use void main()

                    Richard Heathfield wrote:
                    >
                    mrdarrett@gmail .com said:
                    >
                    typedef struct{
                    int i, j;
                    } deStruct;

                    deStruct main()
                    {
                    deStruct k;

                    k.i = 0;
                    k.j = 10;
                    return k;
                    }

                    Crashes when running the compiled code. (I used the Borland C++ 5.5
                    free command line tools)

                    Spectacular, though.
                    >
                    Yeah, I crashed NT4 once with double main, in much the same spirit of
                    enquiry. I was rewarded with lots of blinkenlights. (A text screen
                    appeared, randomly filled, and the flash attribute bit was set on a good
                    many of the character positions.)
                    I tried a triple main, but it wouldn't even compile. :-)

                    --
                    +-------------------------+--------------------+-----------------------+
                    | Kenneth J. Brody | www.hvcomputer.com | #include |
                    | kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer .h|
                    +-------------------------+--------------------+-----------------------+
                    Don't e-mail me at: <mailto:ThisIsA SpamTrap@gmail. com>


                    Comment

                    Working...