View Poll Results: Which type of C++ coder are you?

Voters
12. You may not vote on this poll
  • int main(int args)

    7 58.33%
  • void main(void)

    5 41.67%
Page 1 of 2 12 LastLast
Results 1 to 10 of 19

Thread: int main() vs. void main() - Which do you use?

  1. #1
    Join Date
    Mar 2003
    Posts
    1,700
    Rep Power
    0

    Default int main() vs. void main() - Which do you use?

    This is an age old debate among C++ coders. Personally, I never saw the need for int main. I never saw a logical use for it except for when the main driver module needs to return a parameter for threading purposes. Some people stick to int religiously - whether or not it's useful. Which main are you? Int or Void? And why?

  2. #2
    Join Date
    Oct 2004
    Posts
    4,814
    Rep Power
    24

    Default

    int main() {
    }

    here;

    normal I use it for interoperability with programs that may be written to use or invoke ur executable. Depending on the exit code of the executable the initating app can determine if the invocation was a successful one or a failure. Its good when someone wants to wrap a higher level api around ur exe..

  3. #3
    Join Date
    Jan 2005
    Posts
    3,151
    Rep Power
    0

    Default

    I use int main, as it is always good for your programs to return some useful value.
    People who code shell scripts also would know what I am talking about

    Regards,
    Poogeee

  4. #4
    Join Date
    Mar 2003
    Posts
    1,700
    Rep Power
    0

    Default

    leo

    Good point. You build a lot of servlets don't you?

  5. #5
    Join Date
    Oct 2004
    Posts
    4,814
    Rep Power
    24

    Default

    Quote Originally Posted by Xenocrates
    leo

    Good point. You build a lot of servlets don't you?
    in my days of cgi and java yup... also I find int main() a useful feature.. when others use it in their code for e.g.

    I use subversion to manage my source codes but the subversion server "svnserve" that is needed to interact with subversion could not be installed as a service so it was a headache to manually start the server evreytime you start the server. anyways lucky the exceutable used exist code via int main() so what I did was write a .net services that wraped around the subversion server it was pretty easy to debug and work because it used the int main decalration as well as documented exist codes..

  6. #6
    Join Date
    May 2003
    Posts
    229
    Rep Power
    0

    Default

    I use

    int main(void)

    or

    int main(int argc, char *argv[])

    for the same reasons mentioned by previous posts.

  7. #7
    Join Date
    Jan 2005
    Posts
    3,151
    Rep Power
    0

    Default

    So the void main()ers are ashamed to make themselves known?

  8. #8
    Join Date
    Mar 2003
    Posts
    1,700
    Rep Power
    0

    Default

    I don't think there are many. Personally, I've never been put into a situation where I'd ever need to use int main outside of a situation where I know there's going to be some higher level process - like in the case of threading.

  9. #9
    Join Date
    Jan 2005
    Posts
    3,151
    Rep Power
    0

    Angry

    In unix like systems there are binaries /usr/bin/true and /usr/bin/false
    those two programs basically consist of
    Code:
    int main(void) 
    { 
     return 0; 
    }
    and
    Code:
    int main(void) 
    { 
     return 1; 
    }
    most people would not have a use for them.

    Ref: http://www.maconlinux.net/linux-man-...en/true.1.html

  10. #10
    Join Date
    Oct 2004
    Posts
    4,814
    Rep Power
    24

    Default

    In unix like systems there are binaries /usr/bin/true and /usr/bin/false
    those two programs basically consist of
    LOL.. very funny .

    AUTHOR
    Written by no one.
    REPORTING BUGS
    Report bugs to <bug-coreutils@gnu.org>.
    COPYRIGHT
    Copyright © 2002 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    SEE ALSO
    The full documentation for true is maintained as a Texinfo manual. If the info and true programs are properly installed at your site, the command

    info true

    should give you access to the complete manual.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •