Compiler question

This is a discussion on Compiler question within the C++ Programming forums, part of the General Programming Boards category; Code: int main() { } My compiler doesn't give any warnings when I compile this. Is there something wrong with ...

  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をこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,662
    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,475
    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.
    I'm just trying to be a better person - My Name Is Earl

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

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