Thread: Compiler question

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    65

    Compiler question

    Code:
    int main() {
    
    }
    My compiler doesn't give any warnings when I compile this. Is there something wrong with it, or is it just a feature of main?

  2. #2
    The larch
    Join Date
    May 2006
    Posts
    3,573
    You mean, there is no return?

    Main is a special function and the language standard - I think - requires that main return 0 if not specified explicitly.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    The C++ standard says main returns 0 implicitly if no other value is returned.
    This only applies to main. Any other function that returns any type other than void must explicitly return a value.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    In short, no.

    main() is the first function the operating system calls to envoke the program and that is obviously the starting point of the C/C++ program. If you did not include main then you would get a linker error asking you where it was.
    Double Helix STL

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question about compiler copying objects
    By Sharke in forum C++ Programming
    Replies: 3
    Last Post: 06-15-2009, 08:25 AM
  2. gcc compiler question
    By s_ny33 in forum C Programming
    Replies: 6
    Last Post: 10-18-2005, 07:13 AM
  3. question about bool
    By ssharish2005 in forum C Programming
    Replies: 7
    Last Post: 10-17-2005, 08:18 AM
  4. C/C++ Compiler Question
    By Unregistered in forum C++ Programming
    Replies: 11
    Last Post: 07-09-2002, 02:09 AM
  5. Question: Which Compiler????
    By MaBo in forum C Programming
    Replies: 5
    Last Post: 06-04-2002, 11:57 AM