That has nothing to do with the issue I was referring to.
In that case, you failed to make it clear what you were talking about.
I took it to be "applying recursion safely", but if it did not,
please...
That is the issue I was referring to: there's so portable solution to
determining what initial values are "sensible".
Usually there are. You can inspect the application domain and make an
estimate how deep the recursion could sensibly be. It is application
dependent, but then again, any software is application specific.
Any non-zero "sensible initial value' is definitely platform specific.
Nope, it's application specific, and merely assumes the platform has
enough memory to cope, and that's an assumption inherent to any
program, even your ultra-portable stuff.
If you're not capable of making an estimate of the maximum depth of
reccusion which will occur and how that jives with your target
platforms, every installation of your software is equivalent to just
rolling the dice.
And you don't strike me as a gambler. You rely on SIGSEGV so cap it, I
suggest you cap it yourself, since SIGSEGV is a luxury item on many
platforms.
Don't give me the credit for that decision; it was made by our clients
at a time when C90 was half the age that C99 is now. At the time they
made that choice, C90 was substantially more widely supported than C99
is now, but it was still a decision that cost them significant
portability at that time. If it were up to me, right now, I'd choose C99
and C++98.
And why? Perhaps because you know that version is supported on all
your target platforms? If you're not sure that it's supported across
all your targets, your choice would be irresponsable, and you do not
strike me as being that.
Besides, my point was only to note that target platforms must be
considered, and i consider it made and acknowledged.
The main reason I'd go for a recursive algorithm, when appropriate,
would be maintainability, not performance, because the code would be
easier to write and easier to read. My comments about those
platform-specific capabilities is that I don't like being forced away
from that choice by reason of the existence of platforms where there
wasn't enough stack to support the recursion, unless it's actually
necessary to port my code to such platforms.
Nobody's forcing anybody. You're right o consider readability and
maintainability important objectives. As a matter of fact, so do i.
However in my experience, the difference between recursive and non-
recursive algorithm's isn't that big. Unless of course you merely
produce a kludge instead of a design.
Your use of "if at all possible" is a bit disingenuous. As I'm sure you
already know, it's always possible to avoid recursion; it's never a
mandatory approach - just a convenient one.
Perhaps, and i tend to disagree without your providing some sort of
proof for that suggested theorem. It' also a costly and (at times)
risky one. For the reasons me, you and others have already mentioned.
The risk is in fact what gave rise to this thread.
The advice i provided still seems reasonable.
I'm not aware of any other language that provides a mechanism for
avoiding or dealing with this problem, either. There might be one, but I
don't know it's name.
So why say it's a problem with 'C', when in fact it's a problem in any
given language you know of?
I was thinking more broadly than that: "employing function calls
safely".
Oh, wow...
C provides no mechanism for determining whether or not there's
enough stack left to safely call any function - recursively or not -
note even the initial call to main(). Nor does it provide a mechanism
for dealing with the consequences, if there's not enough stack.
As I said above, I don't know of any other language that provides such
mechanisms, either.
C does not have a mechanism to guarantee 'any' statement will execute
successfully. Nor does any other (compiled) language. In interpreted
languages, however, it's a doddle.
But then again, the interpreter for such a language is compiled and so
the problem is merely shifted. Is there a point in any of this, or are
you merely providing verbal foliage?
Your choice seems insufficiently motivated to me; "arbitrary" is a fine
word for conveying that judgment. It might be a mistaken judgment, but
then the fault is in the judgment, not in the word used to express it.
Well, pigheadedness seems a nice word to describe my judgment, so i'll
guess i'll use that.
Have a nice day. Remind me never to buy your software.