Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

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

Options
  • 15-03-2004 9: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 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 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