C++ Logo


Advanced search

[std-proposals] C++ never had a compiler without a stack

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Mon, 14 Aug 2023 12:44:51 +0100
To my knowledge, there has never been a C++ compiler for a processor
that doesn't have a stack.

You can find some C compilers for some very small microcontrollers
that don't have a stack, but not C++.

So how about we have a function to get the stack pointer, which would
look something like:

    __asm__ (
    #if defined(__i386__) // x86 (32-bit)
        "mo4v %esp, %eax\n"
    #elif defined(__x86_64__) // x86_64 (64-bit)
        "mov %rsp, %rax\n"
    #elif defined(__aarch64__) || defined(__aarch64__) // AArch64 (ARM 64-bit)
        "mov x0, sp\n"
    #elif defined(__arm__) // ARM (32-bit)
        "mov r0, sp\n"
        "bx lr"
    #elif defined(__mips__) // MIPS
        "move $v0, $sp\n"
        "jr $ra"

And also how about we standardise the function "alloca" which allows
us to allocate bytes on the stack? For those not familiar with
'alloca', here's the Linux manual entry:


And here's a quick excerpt from that manual page

       The alloca() function allocates size bytes of space in the stack
       frame of the caller. This temporary space is automatically freed
       when the function that called alloca() returns to its caller.
       Because it allocates from the stack, it's faster than malloc
       and free. In certain cases, it can also simplify memory
       deallocation in applications that use longjmp or siglongjmp.

Received on 2023-08-14 11:45:04