Path: csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Recursion or loop, design questions Date: Fri, 10 Jul 2015 11:50:48 -0700 Organization: None to speak of Lines: 26 Message-ID: References: <60a17017-4fa3-4367-8b88-02038deb499e@googlegroups.com> <559FEA49.9020007@verizon.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="12564"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+E0BZWRmjPU76yi2+90f/a" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:WVKGiFxNCSNQueQR0Hd8Pr/h9HU= sha1:fWOsprMtcxdgwEo1fc9Gy98q4Ag= Xref: csiph.com comp.lang.c:65171 James Kuyper writes: [...] > These terms all refer to the fact that each level of recursion will > generally use up additional memory, and if the recursion goes too far, > it will use up all available memory. The next recursive call will after > that happens will have undefined behavior. The standard provides no > method for detecting whether this will happen, nor whether it has > happened. This is not unique to recursive functions: any function will > have undefined behavior if executed when there's insufficient memory > available to store it's local objects. However, recursive function calls > can make this more likely to happen. [...] True. On the other hand, I think most operating systems guard against stack overflow, so if a function call attempts to allocate more memory (for local variables and so forth) than is currently available, the program will terminate. Are there practical cases where a stack *overflow* can cause problems other than terminating the program? -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"