Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. C++ Program without main()

C++ Program without main()

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pix_programmer
    wrote on last edited by
    #1

    Hi! Is it possible to write a program with out main() function in C++? If yes, Erom where the execution begins for such a program?

    L A 2 Replies Last reply
    0
    • P pix_programmer

      Hi! Is it possible to write a program with out main() function in C++? If yes, Erom where the execution begins for such a program?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Yes, you can by using the Linker /ENTRY[^] option. However, you will not have the full C library initialised so it is your program's responsibility to set the environment correctly.

      speaking as ...

      P 1 Reply Last reply
      0
      • P pix_programmer

        Hi! Is it possible to write a program with out main() function in C++? If yes, Erom where the execution begins for such a program?

        A Offline
        A Offline
        Aescleal
        wrote on last edited by
        #3

        In standard C++ it isn't possible. As Richard mentioned you can specify an entry point for MSVC and other linkers allow you to do the same thing but you'll have a few hurdles to jump: - The parameters to whatever function you define as the entry point will probably not be argc and argv - Depending on the start-up code you're avoiding static and global objects may not be initialised (no great loss though) - The language runtime library, even if linked, probably won't be initialised - Anything that relies on the OS interacting with the language might go screwy (e.g. if new/delete expects allocations to come out of a heap the runtime allocates on start-up) About the only place I've used this trick, had it work and be useful was back programming for Windows 3.1 when I was trying to keep the size of code down to a minimum and I was willing to pay the price for having an emasculated language. Basically if you're happy programming in assembler and using the OS and your own code for everything then then it may have some use.

        A 1 Reply Last reply
        0
        • L Lost User

          Yes, you can by using the Linker /ENTRY[^] option. However, you will not have the full C library initialised so it is your program's responsibility to set the environment correctly.

          speaking as ...

          P Offline
          P Offline
          pix_programmer
          wrote on last edited by
          #4

          Richard MacCutchan wrote: using the Linker /ENTRY[^] I checked the project property pages. It's also empty. From where it comes?

          L 1 Reply Last reply
          0
          • P pix_programmer

            Richard MacCutchan wrote: using the Linker /ENTRY[^] I checked the project property pages. It's also empty. From where it comes?

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Go to the Linker section, click on Advanced, and add your start label name to the Entry Point item.

            speaking as ...

            1 Reply Last reply
            0
            • A Aescleal

              In standard C++ it isn't possible. As Richard mentioned you can specify an entry point for MSVC and other linkers allow you to do the same thing but you'll have a few hurdles to jump: - The parameters to whatever function you define as the entry point will probably not be argc and argv - Depending on the start-up code you're avoiding static and global objects may not be initialised (no great loss though) - The language runtime library, even if linked, probably won't be initialised - Anything that relies on the OS interacting with the language might go screwy (e.g. if new/delete expects allocations to come out of a heap the runtime allocates on start-up) About the only place I've used this trick, had it work and be useful was back programming for Windows 3.1 when I was trying to keep the size of code down to a minimum and I was willing to pay the price for having an emasculated language. Basically if you're happy programming in assembler and using the OS and your own code for everything then then it may have some use.

              A Offline
              A Offline
              Aescleal
              wrote on last edited by
              #6

              Hi Mr. Univoter, any chance you can tell me why you voted me down? This is so I can either/or: - improve my answer and perhaps leaarn how to express myself better next time - learn something - disagree with you and say why and let other people make up their mind I don't do tit for tat univoting so don't let that stand in your way! Ash

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups