Re:Stack size invisibility in C and the effects on "portabil...
by lifthrasiir on Tuesday September 28, 2021 @10:33AM
(#28683263)
As mentioned in the OP though, there is zero guarantee about the stack usage by library functions.
[ Parent
| on HN ]
Re:Stack size invisibility in C and the effects on "portabil...
by nybble41 on Tuesday September 28, 2021 @11:13AM
(#28683762)
There is also no guarantee that the stack is contiguous—see the "-fsplit-stack" GCC option, or search for "segmented stacks". Libraries for coroutines and delimited continuations also routinely segment the stack. A simple API based around easy access to "top of stack", "bottom of stack", and "current stack pointer" addresses is thus non-universal. There may not be a meaningful limit to the amount of stack available, aside from available heap memory or address space. And this can change over time in response to actions other than allocating or freeing memory on the stack.
Re:Stack size invisibility in C and the effects on "portabil...
by OskarS on Tuesday September 28, 2021 @10:39AM
(#28683342)
No, but that's a pretty weak argument not to have them: they're better than nothing. Not all code uses libraries. And if it was part of the C standard, libraries could use them as well: libraries could fail gracefully instead of blowing the stack. Many libraries already do this when malloc fails, after all.
Re:Stack size invisibility in C and the effects on "portabil...
by saagarjha on Tuesday September 28, 2021 @08:51PM
(#28689165)
I have yet to see a library that fails gracefully when malloc fails. Many claim to be able to do so, but usually keel over when actually presented with a failure.
Re:Stack size invisibility in C and the effects on "portabil...
by PerkinWarwick on Tuesday September 28, 2021 @11:00AM
(#28683582)
...or much of anything else. I've seen commercial libraries monkey with processor state in some nasty ways.