Thread: It is not incorrect to use void main

  1. #16
    Registered User foniks munkee's Avatar
    Join Date
    Nov 2001
    Which in itself isn't entirely horrible. It's when you're trying to debug the thing that "has always worked before", because you don't know any better, and it looks like it should work, but for some unexplained reason that you can't grasp, it just doesn't. You're pulling your hair out for hours on end, only to find out that it is caused by some obscure undefined behaviour that you've always taken for granted...
    Your right of course, but I was just imagining the situation were one has written or contributed to a fly by wire system or perhaps the safety systems at a nuclear power plant.
    "Queen and huntress, chaste and fair,
    Now the sun is laid to sleep,
    Seated in thy silver chair,
    State in wonted manner keep."

  2. #17
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Originally posted by foniks munkee
    Your right of course, but I was just imagining the situation were one has written or contributed to a fly by wire system or perhaps the safety systems at a nuclear power plant.
    I figured as much, I was just hoping to god the original poster is never in such a position.

    Hope is the first step on the road to disappointment.

  3. #18

  4. #19
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    >I've used the expression in many programs and no errors have ever occured

    At the start of this thread, the following thought came to mind.
    There are three kinds of people. The ones who learn by reading, the few who learn by observation, and the rest of them have to pee on the electric fence for themselves.
    --Will Rogers

  5. #20
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Hannover, Germany
    If it was 'incorrect' than it wouldn't work. And since it isn't incorrect hence the reason why almost evey compiler in the world accept the statement void main without flashing any errors or warnings - although i don't reccomend using it anymore - and hence the reason why the ANSI C standard doesn't say/recommend something like "void main is not recommended".
    If murder was incorrect, it wouldn't work either. However, it's not incorrect, it's just contrary to our standards.

    ANSI standard says what is allowed. Everything else is non-standard. Like murder is non-standard in our society.

    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.

  6. #21
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Originally posted by Prelude
    Code: Program startup
    1 The function called at program startup is named main. The implementation declares no
      prototype for this function. It shall be defined with a return type of int and with no
        int main(void) { /* ... */ }
      or with two parameters (referred to here as argc and argv, though any names may be
      used, as they are local to the function in which they are declared):
        int main(int argc, char *argv[]) { /* ... */ }
      or equivalent;9) or in some other implementation-defined manner.
    The old ANSI C standard was: "It can be defined with a return type of int"
    In 1999 this line was updated to: "It shall be defined with a return type of int" so all clueless people (like you, momo20016) could understand that only the above 2 formats are valid.

    Guess that didn't work...

  7. #22
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    this is getting annoying...

  8. #23
    S Sang-drax's Avatar
    Join Date
    May 2002
    Göteborg, Sweden
    Originally posted by Frobozz

    If your too lazy to put a return 0; at the end of int main(), then use Visual BASIC.
    Or continue using C++, "return 0;" is not required.
    #include <iostream>
    int main()
      std::cout << "Hi";
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  9. #24
    Green Member Cshot's Avatar
    Join Date
    Jun 2002
    I feel sorry for the poor dude now. I think he got the point
    Try not.
    Do or do not.
    There is no try.

    - Master Yoda

  10. #25
    Join Date
    Sep 2001
    Well, ya know Cshot..void main is like breaking the code or something. No pun intended.

    I reported this thread because I thought the point has long been given and that I thought it was now just turning into a post magnet. Maybe the mods didn't agree. Ah well.
    The world is waiting. I must leave you now.

  11. #26
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002

    Re: It is not incorrect to use void main

    >>If it was 'incorrect' than it wouldn't work.

    Umm i am not going to read this whole thread, but i want to comment on this line.

    Ever tried to thread a metric bolt into a standerd whole, or the other way around? Well MOST of the time it won't work, because its backwards and incorrect, but every now and then, it works. Does this now make it correct? No it doesn't.

  12. #27
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    none of us could say it better then the man himself:

    Can I write "void main()"?
    The definition
    void main() { /* ... */ }

    is not and never has been C++, nor has it even been C. See the ISO C++ standard 3.6.1[2] or the ISO C standard A conforming implementation accepts
    int main() { /* ... */ }

    int main(int argc, char* argv[]) { /* ... */ }

    A conforming implementation may provide more versions of main(), but they must all have return type int. The int returned by main() is a way for a program to return a value to "the system" that invokes it. On systems that doesn't provide such a facility the return value is ignored, but that doesn't make "void main()" legal C++ or legal C. Even if your compiler accepts "void main()" avoid it, or risk being considered ignorant by C and C++ programmers.

  13. #28
    kicking your communist ass isn't 'incorrect' because it 'works' for us

  14. #29
    I lurk
    Join Date
    Aug 2002
    No sense in beating a vapourized horse.
    cprogramming is nothing but a pen of rabid beasts waiting for some poor sap to stroll by touting void main(). Then we unleash the fury/

  15. #30
    Black Mage Extraordinaire VegasSte's Avatar
    Join Date
    Oct 2002
    Going back to a point raised before, I was tought to use void main() when I learnt C last year!! How can you hope to convince people that it is wrong when they still teach people to use it!! I think the exact phrase was " ..void main() is C programming and int main() is C++ programming.."

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. saying hello and 1st question
    By darksys in forum C Programming
    Replies: 12
    Last Post: 10-31-2008, 02:58 PM
  4. seg fault at vectornew
    By tytelizgal in forum C Programming
    Replies: 2
    Last Post: 10-25-2008, 01:22 PM
  5. need help with handelling multiple source files
    By DarkMortar in forum C++ Programming
    Replies: 38
    Last Post: 05-26-2006, 10:46 PM