possible to have 2 main in c
possible to have 2 main in c
can we have 2 main functions in a c program.. if possible tell me how to do ???
Re:possible to have 2 main in c
What do you want to do with that "feature" if it would exist?
Re:possible to have 2 main in c
yeah sure, you can have a hundred of main()s.
well it won't compile, of course, but don't let that stop you
seriously, if you're trying to do something fancy, you should look at c++: namespaces, classes, static functions, virtual methods etc.
or maybe you can make do with function pointers in plain C.
"when all you have is a hammer, every problem starts to look like a nail"
well it won't compile, of course, but don't let that stop you
seriously, if you're trying to do something fancy, you should look at c++: namespaces, classes, static functions, virtual methods etc.
or maybe you can make do with function pointers in plain C.
"when all you have is a hammer, every problem starts to look like a nail"
Re:possible to have 2 main in c
if you make a program that allows you to start at any arbitrary address, you can have thousands of mains. If you make a program that starts all main-like functions with a main-like name, you can have as many as you like. If you want to make a usable application, use only this one entry point. It makes life a lot easier.
Re:possible to have 2 main in c
If it is possible to have more than one main function, could you please explain, how to do so?
Thanks in advance.
Thanks in advance.
Re:possible to have 2 main in c
For Linux (example):Guest wrote: If it is possible to have more than one main function, could you please explain, how to do so?
Thanks in advance.
Code: Select all
int main(int argc, char **argv) {
if (fork()) {
main1(argc, argv);
} else {
main2(argc, argv);
}
}
Re:possible to have 2 main in c
There's no practical use for two mains, anyway. You could do it just to be clever, but cleverness doesn't make for a good code.
"when all you have is a hammer, every problem starts to look like a kitten"
"when all you have is a hammer, every problem starts to look like a kitten"
Re:possible to have 2 main in c
That's animal abuse! And, misquoting.Andrew_Baker wrote: "when all you have is a hammer, every problem starts to look like a kitten"
"when all you have is a hammer, every problem starts to look like a nail"
-
- Member
- Posts: 1600
- Joined: Wed Oct 18, 2006 11:59 am
- Location: Vienna/Austria
- Contact:
Re:possible to have 2 main in c
In C I dare say having two main() functions is 1. waste, 2. food for the compiler to complain a lot about. Which of the two shall it link against crt0.o? Ha?
So, short conclusion: Forget about using 2 main() in a c program.
@andrew_baker:weird humour is your mark, it seems *g*. A look at voodoo girl proves that. but anyway, don't throw hammers at kittens. they are so cute. Nails are better.
So, short conclusion: Forget about using 2 main() in a c program.
@andrew_baker:weird humour is your mark, it seems *g*. A look at voodoo girl proves that. but anyway, don't throw hammers at kittens. they are so cute. Nails are better.
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
BlueillusionOS iso image
Re:possible to have 2 main in c
I agree, stabbing rusty 9" nails through them is less messy than crushing them with a hammer ;]beyond infinity wrote:Nails are better.
Rated R.