[fpc-pascal] alloca

Michael Van Canneyt michael at freepascal.org
Sat May 14 08:03:28 CEST 2022



On Sat, 14 May 2022, Hairy Pixels via fpc-pascal wrote:

>
>
>> On May 13, 2022, at 11:08 PM, Michael Van Canneyt via fpc-pascal <fpc-pascal at lists.freepascal.org> wrote:
>> 
>>> Is there an “alloca" like function in the RTL which allocates memory from the stack? For example https://man7.org/linux/man-pages/man3/alloca.3.html
>> 
>> No such function exists in FPC.
>
> Is alloca something which is part of the OS or can this be implemented by programmers or used from other libraries?

As far as I can see, it can only be implemented in the compiler.
Only the compiler knows how much stack it uses for a certain routine. 
the alloca needs to interact with this. FPC also has the nostackframe
modifier, inline modifier: all things which in general interact with the
stack.

The man page you refer to hints at this, it says the alloca function is
compiler-dependent and machine-dependent. It names so many pitfalls that I
would not recommend its use. If you think you need this, better declare an
array of bytes of a sufficient size and use that.

Michael.


More information about the fpc-pascal mailing list