Reason # %ld not to use void main()

Discussion in 'C Programming' started by mrdarrett@gmail.com, Jan 2, 2008.

  1. Guest

    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
    , Jan 2, 2008
    #1
    1. Advertising

  2. 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.
    Martin Ambuhl, Jan 2, 2008
    #2
    1. Advertising

  3. Guest

    On Jan 2, 2:55 pm, Martin Ambuhl <> wrote:
    > 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
    , Jan 2, 2008
    #3
  4. In article <>,
    Martin Ambuhl <> wrote:
    > 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.
    Kenny McCormack, Jan 2, 2008
    #4
  5. 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.
    Martin Ambuhl, Jan 2, 2008
    #5
  6. andreyvul Guest

    On Jan 2, 6:04 pm, 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.
    andreyvul, Jan 3, 2008
    #6
  7. Guest

    On Jan 2, 6:54 pm, andreyvul <> wrote:
    > On Jan 2, 6:04 pm, 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
    , Jan 3, 2008
    #7
  8. 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
    Richard Heathfield, Jan 3, 2008
    #8
  9. Guest

    On Jan 2, 11:57 pm, Richard Heathfield <> wrote:
    > 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
    , Jan 3, 2008
    #9
  10. Richard Heathfield wrote:
    >
    > 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:>
    Kenneth Brody, Jan 4, 2008
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ollej Reemt
    Replies:
    7
    Views:
    518
    Jack Klein
    Apr 22, 2005
  2. Stig Brautaset

    `void **' revisited: void *pop(void **root)

    Stig Brautaset, Oct 25, 2003, in forum: C Programming
    Replies:
    15
    Views:
    786
    The Real OS/2 Guy
    Oct 28, 2003
  3. Replies:
    5
    Views:
    824
    S.Tobias
    Jul 22, 2005
  4. int main(void) Why void?

    , Apr 6, 2006, in forum: C Programming
    Replies:
    6
    Views:
    501
  5. Replies:
    1
    Views:
    403
    Victor Bazarov
    May 23, 2007
Loading...

Share This Page