void main

This is a discussion on void main within the A Brief History of Cprogramming.com forums, part of the Community Boards category; Ah yes, the infamous discussion. Ignore this thread if you wish, I just thought I'd post my thoughts which got ...

  1. #1
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765

    void main

    Ah yes, the infamous discussion.
    Ignore this thread if you wish, I just thought I'd post my thoughts which got me thinking on the topic.

    int main()
    7 letters
    return 0;
    6 letters and a number, 7 keys

    A total of 14 characters for int main / return 0.

    void main()
    8 letters
    return;
    6 letters

    A total of 14 characters.

    int main()
    7 again - not returning anything ( small program )

    void main
    8 again - not returning anything ( small program )

    It actually isn't harder to say int main, it's equal when returning something, and easier when not. It's also safer.

    Void main, is truly wrong.
    The world is waiting. I must leave you now.

  2. #2
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    I have never and never will use void main()...

    I have a habbit of typing this as soon as I start a project

    Code:
    #include <iostream.h>
    
    int main()
    {
    
       cin.get();
       return 0;
    }
    Sometimes... I wake up and my fingers are typing this out on my mattress...
    What is C++?

  3. #3
    Seņor Member
    Join Date
    Jan 2002
    Posts
    561
    Your logic is off. I was taught that int main was the same as void main. I don't use void main anymore, but when I did, I never put a return statement. Return isn't necessary with void main.

  4. #4
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    > Return isn't necessary with void main.
    And a program is not needed unless it returns something.

    A simple example:
    I created a menu program for a fair amount of dos based classic pc games. I would check how the execution went, and display more user friendly messages if something went wrong. Because one of the games were programmed by void main programmers, I couldn't detect this. So not only were they not included into my menu for choices, but they also got deleted off my hard drive for the trouble.

    [ / End slam of ID software's early days ]
    The world is waiting. I must leave you now.

  5. #5
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    Should make that..

    #include <iostream.h>

    into

    #include <iostream>

    For the same reason as not having void main.. it's non-standard.
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  6. #6
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    >I was taught that int main was the same as void main.

    Which is simply wrong. There are two forms of main defined in the standard:

    int main()
    int main( int argc, char* argv[] )

    Everything else is wrong. Your compiler may accept it, and build a workaround internally, but that doesn't mean it's correct. It's like running a red light at night. Probably safe, but still you shouldn't do it.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  7. #7
    Registered User toaster's Avatar
    Join Date
    Apr 2002
    Posts
    161
    what about compilers that require you to prototype or declare or initialize ecetra the main(argument(s))?

    Code:
    //sample
    
    #include<stdio.h>
    using namespace std;
    
    int main(int argc, char *argv[]);
    
    int main(int argc, char *argv[])
    {
     printf("this is what you are running: %s", argv[0]);
     // code
     return 0;
    }
    think only with code.
    write only with source.

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,855
    > what about compilers that require you to prototype
    Which compiler needs this?

    You shouldn't need to do this

  9. #9
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,493

    Re: void main

    Originally posted by Shadow
    Void main, is truly wrong.
    whoa...

  10. #10
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    I cant use

    #include <iostream>

    cause Borland will not accept

    using namespace std;

    it has an error that says namespace expected
    What is C++?

  11. #11
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    int main()
    7 letters
    return 0;
    6 letters and a number, 7 keys

    A total of 14 characters for int main / return 0.

    void main()
    8 letters
    return;
    6 letters

    A total of 14 characters.
    It'd be nice if you were consistant..

    int main()
    9 keypresses
    return 0;
    9 keypresses

    void main()
    11 keypresses
    return;
    7 keypresses

    That's 18 and 18!

  12. #12
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,493
    you forgot the enter key...

  13. #13
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    Ouch.. a compiler that doesn't accept namespaces? Honestly, I think it's time to upgrade.
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  14. #14
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Originally posted by ygfperson
    you forgot the enter key...
    And the shift key
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  15. #15
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,230
    But sum d00d who sed he was a VB MASTRE tlod me taht void main() was rite and all the ****ers who say itn main() is right r jsut P0S3R5 who should bow 2 our 1337nes@!

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 03-05-2009, 10:25 AM
  2. can someone help me with these errors please code included
    By geekrockergal in forum C Programming
    Replies: 7
    Last Post: 02-10-2009, 02:20 PM
  3. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  4. need help with handelling multiple source files
    By DarkMortar in forum C++ Programming
    Replies: 38
    Last Post: 05-26-2006, 11:46 PM
  5. getting a headache
    By sreetvert83 in forum C++ Programming
    Replies: 41
    Last Post: 09-30-2005, 06:20 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21