Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

is it possible to have multiple main methods in visual c++?

  • 15-03-2004 09:28PM
    #1
    Closed Accounts Posts: 1,525 ✭✭✭


    just wondering, it seems pretty obvious.
    However i can only seem to get one to work. Anyone know?


Comments

  • Closed Accounts Posts: 104 ✭✭GiMiC


    I don't think it's possible. The main method (or winmain, for Windows programs) is the entry point for the program, so if there were more than one the compiler would have no idea where to begin execution. There could be some trick to work around that though, so don't take my word for it :D


  • Closed Accounts Posts: 437 ✭✭casper-


    Originally posted by vorbis
    just wondering, it seems pretty obvious.
    However i can only seem to get one to work. Anyone know?

    It doesn't really seem obvious .. the linker needs to know the starting address to execute when the program is loaded into memory.

    Btw, why would you want multiple main methods? :)


  • Closed Accounts Posts: 1,502 ✭✭✭MrPinK


    Sounds like you may want a multithreaded programme. You'd have one main method that starts multiple threads of execution running simultaneously.


  • Registered Users, Registered Users 2 Posts: 1,372 ✭✭✭silverside


    as has been said

    you can only have one main() method, otherwise the compiler doesn;t know which one to launch.

    You can call them different things (myMain, myGrandadsMain, mainForSunnyDays) and call them from the real main() function. What are you trying to do??


  • Closed Accounts Posts: 1,525 ✭✭✭vorbis


    was a bit used to eclipse thats all. I thouoght you could use multiple main methods to test parts of a project separately. Otherwise it tries to compile everything at once.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 1,372 ✭✭✭silverside


    use #ifdef statements and/or rename the main's to main1(), main2(), main3() and call them from existing main() function. shouldnt be a big change.


Advertisement