Date: Tue, 9 Jun 2026 14:40:52 +0200
Then any constructs, which dynamically allocate stack space have to be forbidden or need an upper limit.
- no implementation specific alloca()
- no recursion
- function pointers including virtual functions only from a pre-defined set
- interrupt handlers only with a separate stack
It should be possible to create a finite tree of possible calls and assign a fixed amount of stack space.
If this is possible, then instead of stack frames, one could use fixed memory locations.
Only with an optimizer looking deeply into the functions and the conditions, why other functions are called, variable stack frames could be more memory optimal:
main->A->B is possible (if condition is true)
main->A->B->D is never possible
main->B->D is possible (if condition is false)
A non-optimizing system would reserve stack space for main->A->B->D. An optimizing system would use different locations for the stackframe for B, depending on whether main->A->B or main->B->D is currently executed.
bool condition;
void A() {
if (condition)
B();
else
C();
}
void B() {
if (!condition)
D();
}
int main() {
condition = ...;
A();
B();
return 0;
}
-----Ursprüngliche Nachricht-----
Von:Rainer Deyke via Std-Proposals <std-proposals_at_[hidden]>
Gesendet:Di 09.06.2026 13:44
Betreff:Re: [std-proposals] Float the idea: First-class effect annotations and resource contracts for C++
An:std-proposals_at_[hidden];
CC:Rainer Deyke <rainerd_at_[hidden]>;
On 6/8/26 17:28, Arthur O'Dwyer via Std-Proposals wrote:
> [[=stack_usage(256)]] void g() { }
> [[=stack_usage(512)]] void h();
> [[=stack_usage(1024)]] void f() {
> { char buf[1024]; g(); }
> h();
> }
> Does `f` use 1024 bytes of stack, 1024+256 bytes, 1024+512 bytes, or
> 1024+512+256 bytes?
Assuming a halfway competent optimizer, it uses up to somewhat more than
512 bytes. The call to 'g' is inlined and optimized away and the 'buf'
variable is optimized away, so we're left with the call to 'h', which is
declared to take 512 bytes, plus the non-zero stack space used by the
function call itself. It is not possible to know how much stack space a
function actually uses in a portable manner just by looking at it, but
it's possible for the compiler to verify an upper limit to stack usage
in some cases.
--
Rainer Deyke - rainerd_at_[hidden]
--
Std-Proposals mailing list
Std-Proposals_at_[hidden]
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
Received on 2026-06-09 12:44:13
