C++ program without main()

Aug 17, 2009 at 12:21am


The main() function is the starting point for a program execution in Cpp.
Is it possible to run a program without the main() function ? Every time I try it, my compiler shuts down instantaneously.
Just Curious !!
Aug 17, 2009 at 12:23am
To create a true standalone program you need a main function of some kind as far as I know.
Aug 17, 2009 at 12:23am
It's not possible to run a program without main, but you CAN do this:

1
2
3
4
5
6
7
8
9
10
11
void program( );
int main( ){
   program( );
   return 0;
}



void program( ){
   // put whatever your program does here
}
Aug 17, 2009 at 12:25am
I really doubt it. If it's truly possible then I'll write an operating system in HTML.
Aug 17, 2009 at 12:39am
Sounds sane ..
Aug 17, 2009 at 2:17am
It is certainly possible. However, if you want to use something other than main(), you'll have to do some assembly programming to replace the C runtime (CRT) that executes your main() function.

This gives the gist of what has to be done: http://sourceware.org/ml/crossgcc/2000-08/msg00010.html

Aug 17, 2009 at 2:36am
I was getting worried, but I'm not counting ASM.
Aug 17, 2009 at 4:47pm
It is not possible to make a program without the main() function.
A C++ program starts at the main function first. Don't you know curiosity killed the cat!

Also there is a HTML OS out there sort of... Pspwxp, just some pages with flash
See this http://www.youtube.com/watch?v=R4Qq_TXtlZo
Last edited on Aug 17, 2009 at 4:51pm
Aug 17, 2009 at 6:57pm
I meant a real, bootable OS. And if you open up a program in a text editor, it's HTML.
Topic archived. No new replies allowed.