void main() return error code 0 ?

This is a discussion on void main() return error code 0 ? within the C Programming forums, part of the General Programming Boards category; Well, I know void main() is evil, and we shud use int main()...but if I do use void main(), then ...

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    28

    void main() return error code 0 ?

    Well,

    I know void main() is evil, and we shud use int main()...but if I do use void main(), then what?? What "error code" does it return to the OS? zero ??

    (Note: I cud have tested it myself, but I dont have a C compiler installed on the current system yet..)

    :-)

    Thanks.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Well, seeing as how you don't specify a return value it's undefined what actually gets returned. Translation: most likely a random value that could do anything.

    -Prelude
    My best code is written with the delete key.

  3. #3
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    Why do ppl still use it? And what's its use anyway?

  4. #4
    Registered User foniks munkee's Avatar
    Join Date
    Nov 2001
    Posts
    343
    Well, one reason that people still use it is that there are still text books out there teaching it.. and they don't go to any lengths to explain why undefined behaviour is so undesireable.

    Incidently under C89 standards returning anything from main other than an int causes undefined behaviour.

    Under C99 it causes unspecified behaviour (only if the compiler is designed to do so) otherwise its undefined.

    There are three portable return values from main()

    0
    EXIT_SUCCESS
    EXIT_FAILURE

    The last two are defined in stdlib.h

    PS: It is possible to cause some really catastrophic failures by using void main(). I have heard some real horror stories.

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >Why do ppl still use it?
    The evidence suggests that they don't care.

    >And what's its use anyway?
    The only use is to get a rush from taking the risk.

    >I have heard some real horror stories.
    I saw a monitor that was actually fried by the use of void main. The program returned an invalid value which was construed as a very high number by the controller on the moniter which required a constant voltage. The voltage was changed and the monitor fizzled.

    -Prelude
    My best code is written with the delete key.

  6. #6
    Registered User foniks munkee's Avatar
    Join Date
    Nov 2001
    Posts
    343
    Hell, that is impressive - I new a guy who had his hard drive reformated. Not happy at all

  7. #7
    Linguistic Engineer... doubleanti's Avatar
    Join Date
    Aug 2001
    Location
    CA
    Posts
    2,459
    wow... are you serious? wow... if anyone ever says they don't wanna use int main (), just tell em that story... wow... how would that ever happen [the fried monitor]? i might understand a format, if the guy chained into format.com and the stars aligned, but wow...
    hasafraggin shizigishin oppashigger...

  8. #8
    Registered User foniks munkee's Avatar
    Join Date
    Nov 2001
    Posts
    343
    Yeah - as the author of one book put it (Reckon is was C Unleashed):

    ..If you void main() and you're writing code for a nuclear reactor or a military aircraft, your probably feeling a little unsettled right now, and I don't blame you.
    The author also recounts a story of lost hard drives from this very thing.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inserting a swf file in a windows application
    By face_master in forum Windows Programming
    Replies: 12
    Last Post: 05-03-2009, 11:29 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, 01:20 PM
  3. ChangeDisplaySettings - Blank?
    By Tonto in forum Windows Programming
    Replies: 13
    Last Post: 12-26-2006, 03:17 PM
  4. Quack! It doesn't work! >.<
    By *Michelle* in forum C++ Programming
    Replies: 8
    Last Post: 03-01-2003, 11:26 PM

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