POV-Ray : Newsgroups : povray.off-topic : Curious C / C++ defined behavior question : Re: Curious C / C++ defined behavior question Server Time
30 Jul 2024 00:25:35 EDT (-0400)
  Re: Curious C / C++ defined behavior question  
From: Lars R 
Date: 29 Jun 2011 03:44:09
Message: <4e0ad7c9@news.povray.org>
>>> Does the standard say anything about how deeply nested calls can
>>> recurse?
>>
>> Partially: At least 2, because it says that functions can be called
>> recursively. :-)
> 
> Heh heh heh. That's a point.
> 
>> there are a lot of limits and other limitations where "no diagnostic is
>> required". But I cannot find anything about a maximum of function call
>> nesting levels, neither in C++ 2003 nor in C 99.
> 
> See, that bothers me.

Me too.

> Because it implies a function call will always
> succeed, because they didn't say it might fail but they do tell you the
> semantics of it succeeding.  That's why I wondered what kind of wording
> they were using.

Indeed.

I'd suggest something like “A recursion depth of at least 5 must be
supported by the platform. The actual limit might be higher and can be
determined by ...”

But such guarantee is not easily definable because the size of the
function parameters is not limited (only their number). On most
platforms the function parameters live on the CPU stack (when the
registers that are used for parameter transfer are exhausted). That
stack is on most platforms much smaller than the available memory, but
its size cannot be determined in a ISO-C++-compliant way.

So even a recursion “depth” of 1 might fail in such pathetic cases.

But statements like “Every function call might fail due to reasons that
are out of scope of this standard“ are also not sensible, I think.

Any other options or opinions? –.–

Lars R.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.