Remix.run Logo
eikenberry 18 hours ago

Is there a language that makes this explicit, allocates the variables on the stack via compiler enforced notation?

fanf2 18 hours ago | parent | next [-]

C, C++, Rust, Zig, …

eikenberry 12 hours ago | parent [-]

What's Zig's notation for it?

masklinn 8 hours ago | parent [-]

Not doing anything, same as the other 3.

Heap allocation is what requires requesting memory from an allocator.

neonsunset 18 hours ago | parent | prev [-]

C# (.NET in general) :)

Well, variables cannot be forced to stack specifically. They are placed in the "local scope". And that would usually be either stack or CPU registers - thinking in stack only is a somewhat flawed mental model.

Both C# and F# complicate this by supporting closures, iterator and async methods which capture variables placing them in a state machine box / display class instead which would be located on the heap, unless stack-allocated by escape analysis (unlikely because these usually cross method boundaries).

However, .NET has `ref structs` (or, in F#, [<Struct; IsByRefLike>] types) which are subject to lifetime analysis and can never be placed on the heap directly or otherwise.