From: "Martin Peach" Newsgroups: comp.os.msdos.djgpp Subject: Re: Use of recursion Date: Sun, 12 Dec 1999 13:42:08 -0500 Organization: Communications Accessibles Montreal, Quebec Canada Lines: 19 Message-ID: <830qak$s8k@tandem.CAM.ORG> References: <82vfqn$6ce$1 AT mango DOT singnet DOT com DOT sg> NNTP-Posting-Host: dialup-6.hip.cam.org X-Newsreader: Microsoft Outlook Express 4.72.3110.5 X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com >When should I use recursion since it can be replaced with looping >most of the time? I think that recursion can be dangerous because of the possibility of stack overflow, which is a weak spot in most computer architectures, in that the cpu blindly allocates memory to the stack without first checking to see if it is available (as opposed to allocating memory from a heap, where you can check to see if it's there before jumping in), in other words, your code becomes much less robust as it loses most of the protection afforded by the "protected mode". An architecture that uses a separate memory space for the stack would be preferable, but that doesn't seem to be in the works, except for some DSPs, which usually have such tiny stack spaces that you can hardly call functions, let alone do it recursively. \/\/\/*= Martin