Thread: why no need to return a value in GNU C/C++ ??

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    113

    Question why no need to return a value in GNU C/C++ ??

    I'm using gcc 4.4.1 C/C++ compiler for programming in Ubuntu.
    The thing I noticed is,
    The program works with no errors even though I don't type the function to be as ' void main ' or ' return 0 ' ( or return any value) at the end of the program..
    It absloutely works !!

    But not in Turbo C/C++ IDE ( which we use in Windows ), a DOS compiler !!

    Why ???

  2. #2
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,534
    Try using the -Wall and -Wextra switches when you compile, and see what happens then. BTW, void main is never valid, at any time - main returns an int.

  3. #3
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    639
    Quote Originally Posted by suryak View Post
    I'm using gcc 4.4.1 C/C++ compiler for programming in Ubuntu.
    The thing I noticed is,
    The program works with no errors even though I don't type the function to be as ' void main '
    Because leaving out 'void main' is the only good thing you can do with it.
    or ' return 0 ' ( or return any value) at the end of the program..
    Because C++ doesn't require return at the end of main
    But not in Turbo C/C++ IDE ( which we use in Windows ), a DOS compiler !!

    Why ???
    Because Turbo C++ was made before there was an agreement as to what constituted C++, also it's rubbish.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. why can't my perceptron learn correctly?
    By yann in forum C Programming
    Replies: 25
    Last Post: 10-15-2010, 12:26 AM
  2. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  3. Another weird error
    By rwmarsh in forum Game Programming
    Replies: 4
    Last Post: 09-24-2006, 10:00 PM
  4. Why only 32x32? (OpenGL) [Please help]
    By Queatrix in forum Game Programming
    Replies: 2
    Last Post: 01-23-2006, 02:39 PM
  5. opengl help
    By heat511 in forum Game Programming
    Replies: 4
    Last Post: 04-05-2004, 01:08 AM

Tags for this Thread