main() return values and exit()

This is a discussion on main() return values and exit() within the C Programming forums, part of the General Programming Boards category; What exactly is the advantage of using: int main() over using: void main() And if returning a value is better, ...

  1. #1
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913

    main() return values and exit()

    What exactly is the advantage of using:
    int main()
    over using:
    void main()
    And if returning a value is better, why? Also - if returning a value holds an advantage, how does it rank with stlib.h's exit(0)?

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,417
    Read some of the topics on this page
    http://www.eskimo.com/~scs/C-faq/s11.html

  3. #3
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Well that asnwered my first question - thanks - but is there any difference between exit(0) and return 0?

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,417
    You mean
    http://www.eskimo.com/~scs/C-faq/s11.html

    Better read the whole damn thing

  5. #5
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,639
    There is one big difference between exit and return. Exit will cause the program to terminate even from within a function whereas return does not ( necessarily )...
    Code:
    if( numeric_limits< byte >::digits != bits_per_byte )
        error( "program requires bits_per_byte-bit bytes" );
    24bbs.cpp

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 10:06 AM
  2. Another weird error
    By rwmarsh in forum Game Programming
    Replies: 4
    Last Post: 09-24-2006, 10:00 PM
  3. Why only 32x32? (OpenGL) [Please help]
    By Queatrix in forum Game Programming
    Replies: 2
    Last Post: 01-23-2006, 01:39 PM
  4. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  5. problem with open gl engine.
    By gell10 in forum Game Programming
    Replies: 1
    Last Post: 08-21-2003, 04:10 AM

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