Recursion with main()

S

Sonia

quick Question. Can main() function be called recursively. Anything wrong
with calling it recursively ?

Thanks
 
A

Artie Gold

Sonia said:
quick Question. Can main() function be called recursively. Anything wrong
with calling it recursively ?
Recursive `main()' is *not* legal in standard C++.

<OT>It *is* legal in C, but *rarely* a Good Idea.</OT>

HTH,
--ag
 
J

John Harrison

Sonia said:
quick Question. Can main() function be called recursively. Anything wrong
with calling it recursively ?

Thanks

It is specifically forbidden in C++ (for some reason that's never been
adequately explained to me). But there is nothing wrong with this

int pseudo_main()
{
...
pseudo_main();
}

int main()
{
return pseudo_main();
}

john
 
K

Kevin Goodsell

John said:
It is specifically forbidden in C++ (for some reason that's never been
adequately explained to me).

Well, I don't know if this is adequate or even precisely accurate, but
my understanding is that implementations can stick all kinds of
initializations stuff in at the beginning of main(), and if that stuff
were executed more than once the results could be bad.

Of course, I don't see any good reason that an implementation could not
do precisely what you did in your reply. Perhaps this point makes this
explanation inadequate.

-Kevin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
474,142
Messages
2,570,817
Members
47,363
Latest member
eitamoro

Latest Threads

Top