Can I write a program in C or in C++ with two main functions?
The idiom is to dispatch on the value of argv[0]
. With hardlinks (POSIX) you don't even lose diskspace.
Yes; however, it's platform specific instead of standard C, and if you ask about what you really want to achieve (instead of this attempted solution to that problem), then you'll likely receive answers which are more helpful for you.
No, a program can have just 1 entry point(which is main()
). In fact, more generally, you can only have one function of a given name in C.
No, you cannot have more than one main() function in C language. In standard C language, the main() function is a special function that is defined as the entry point of the program. There cannot be more than one copy of ANY function you create in C language, or in any other language for that matter - unless you specify different signatures. But in case of main(), i think you got no choice ;)