POV-Ray : Newsgroups : povray.off-topic : Curious C / C++ defined behavior question : Re: Curious C / C++ defined behavior question Server Time
29 Jul 2024 18:16:58 EDT (-0400)
  Re: Curious C / C++ defined behavior question  
From: Darren New
Date: 22 Jun 2011 18:16:44
Message: <4e0269cc$1@news.povray.org>
On 6/22/2011 14:32, Warp wrote:
> Darren New<dne### [at] sanrrcom>  wrote:
>> On 6/22/2011 13:07, Warp wrote:
>>> (but the end result is probably an abort()).
>
>> I would be very, very surprised if it wasn't undefined behavior to violate
>> the limits of the stack space.  There's just no good efficient portable way
>> of checking on hardware that doesn't do per-access checks (i.e., like a Z80
>> or something).
>
>    You can violate any space by poking with pointers and offset at wild,
> but the question was what happens if a function recurses too much and the
> function calls run out of stack space.

I was aware of what question I asked, yes. :)

>    The official standard probably defines it as either undefined behavior
> or implementation defined, but in practice what happens in most systems
> is that the C runtime asks the OS to increase the stack space for that
> process, the OS says nope, and then the C runtime aborts with some message.

In most multitasking systems with virtual memory running user-space 
applications, yes. And my point is that I don't think there's anything in 
the standard that's going to restrict C to that sort of machine.

In practice, under UNIX and Windows and such, yes, that's what happens. On 
the Amiga 1000? On a Z-80 or 68000 or 8086? No, that's not what happens.

>    AFAIK in most systems the C runtime does indeed ask the OS to increase
> the stack space as needed (in a similar way as it asks the OS to increase
> heap space as needed).

Again, assuming you're talking about a multi-user virtual-memory-based 
operating system with demand paging, implying the hardware has per-access 
memory checking.  On systems without per-access memory checking, you don't 
get that, and it would be odd to include in the standard something that 
would have egregious overhead to enforce on low-end hardware.

Am I missing something?  Was I unclear, or were you just not paying as much 
attention as you usually do?  (Serious question, not intended as a 
criticism. I'm just trying to improve my communication skills.)

-- 
Darren New, San Diego CA, USA (PST)
   "Coding without comments is like
    driving without turn signals."


Post a reply to this message

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