C++ Program without main()
-
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?
-
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?
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.
-
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?
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.
-
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.
Richard MacCutchan wrote: using the Linker /ENTRY[^] I checked the project property pages. It's also empty. From where it comes?
-
Richard MacCutchan wrote: using the Linker /ENTRY[^] I checked the project property pages. It's also empty. From where it comes?
Go to the Linker section, click on Advanced, and add your start label name to the Entry Point item.
-
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.
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