> On May 14, 2022, at 1:03 PM, Michael Van Canneyt via fpc-pascal 
> <fpc-pascal@lists.freepascal.org> wrote:
> 
> 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.

Apparently what it does is advance the stack pointer x bytes and return a 
pointer to the new location so you could probably do that with some assembly. 
Of course this is dangerous because you can request more memory than exists in 
the current frame.

The reason I wanted to try this was because I saw some C++ example where the 
overrode the new operator and used alloca instead of malloc (like overriding 
NewInstance in FPC) and I thought this would be an interesting solution for 
some classes and just a fun experiment to play with.

Regards,
        Ryan Joseph

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to