Why do people still use main() or main(void)?

This is a discussion on Why do people still use main() or main(void)? within the C Programming forums, part of the General Programming Boards category; So why do people continue to use main() and main(void)? without int If you don't need argc and argv? Are ...

  1. #16
    Registered User
    Join Date
    Oct 2006
    Posts
    250
    So why do people continue to use main() and main(void)? without int
    If you don't need argc and argv?
    Are you serious?

    What do argc, and argv have to do with main's return type?

  2. #17
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    brewbuck is referring to main()'s parameters. I think the OP is referring to both main()'s return type and parameters, but in that case, I think the question was related to the return type being implicitly declared as int.

  3. #18
    Registered Abuser
    Join Date
    Jun 2006
    Location
    Toronto
    Posts
    591
    So why do people continue to use main() and main(void)? without int
    Mostly out of laziness/ignorance, but that doesn't mean there isn't a valid reason for not using int main(void). For example, programming for embedded systems may often include "non-standard" code, such as void main(void).

    As for the implicit return of 0, I personally always make use of this unless I intend on returning a specific result. This is beneficial, because in the future, if the standards committee decides that main will now return X by default instead of 0, or will return X and perform some clean-up code, then you no longer have to worry about correcting all the "return 0"'s you hard-coded into your source in the past.

  4. #19
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Quote Originally Posted by @nthony View Post
    As for the implicit return of 0, I personally always make use of this unless I intend on returning a specific result. This is beneficial, because in the future, if the standards committee decides that main will now return X by default instead of 0, or will return X and perform some clean-up code, then you no longer have to worry about correcting all the "return 0"'s you hard-coded into your source in the past.


    this is highly unlikely due to this functioning in scripts:

    Code:
    app
    if(!ret_val) echo error!
    it would instantly invalidate every C program and most scripts, making a lot of work for people to recode their programs and scripts, making a lot of programmers and scripters unhappy.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory leaks problem in C -- Help please
    By Amely in forum C Programming
    Replies: 14
    Last Post: 05-21-2008, 11:16 AM
  2. Bush vs. Kerry
    By jlou in forum A Brief History of Cprogramming.com
    Replies: 178
    Last Post: 11-29-2004, 02:45 PM
  3. int main (), main (), main (void), int main (void) HELP!!!
    By SmokingMonkey in forum C++ Programming
    Replies: 7
    Last Post: 05-31-2003, 09:46 PM
  4. what to do with the main window
    By stallion in forum Windows Programming
    Replies: 2
    Last Post: 01-28-2003, 07:58 PM
  5. Language
    By nvoigt in forum A Brief History of Cprogramming.com
    Replies: 19
    Last Post: 04-29-2002, 02:28 PM

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