Connecting Tech Pros Worldwide Help | Site Map

Recursion with main()

  #1  
Old July 19th, 2005, 05:57 PM
Sonia
Guest
 
Posts: n/a
quick Question. Can main() function be called recursively. Anything wrong
with calling it recursively ?

Thanks


  #2  
Old July 19th, 2005, 05:57 PM
Artie Gold
Guest
 
Posts: n/a

re: Recursion with main()


Sonia wrote:[color=blue]
> quick Question. Can main() function be called recursively. Anything wrong
> with calling it recursively ?
>[/color]
Recursive `main()' is *not* legal in standard C++.

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

HTH,
--ag




--
Artie Gold -- Austin, Texas

  #3  
Old July 19th, 2005, 05:57 PM
John Harrison
Guest
 
Posts: n/a

re: Recursion with main()



"Sonia" <smach02@hotmail.com> wrote in message
news:UyO4b.4575$UF.2204@bignews2.bellsouth.net...[color=blue]
> quick Question. Can main() function be called recursively. Anything wrong
> with calling it recursively ?
>
> Thanks
>[/color]

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


  #4  
Old July 19th, 2005, 05:58 PM
Kevin Goodsell
Guest
 
Posts: n/a

re: Recursion with main()


John Harrison wrote:
[color=blue]
> "Sonia" <smach02@hotmail.com> wrote in message
> news:UyO4b.4575$UF.2204@bignews2.bellsouth.net...
>[color=green]
>>quick Question. Can main() function be called recursively. Anything wrong
>>with calling it recursively ?
>>
>>Thanks
>>[/color]
>
>
> It is specifically forbidden in C++ (for some reason that's never been
> adequately explained to me).[/color]

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
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
segmentation fault in recursion asit answers 14 January 18th, 2008 07:15 PM
Backtracking Recursion Problem NOO Recursion answers 12 February 22nd, 2007 02:05 AM
Is main a registered word small TUX answers 20 December 11th, 2006 07:35 AM
main(int argc, char *argv[]) Sokar answers 13 November 14th, 2005 09:48 PM