Re: alloca



Keith Thompson wrote:
....
For example, a compiler can decide to _always_ perform the calls to
argument-forming functions before starting to form the next stack
frame. (no need to single out the 'alloca').

No, a compiler that provides alloca() *doesn't* have to make sure that
the argument passing mechanism works correctly. Since no standard
defines the behavior of alloca(), a compiler is free to leave its
behavior undefined in any circumstances where making it work would be
inconvenient.
...

That's just another way to circumvent the potential problem with using 'alloca' in an argument list. Just say that behavior is undefined in this case. A quality implementation might perform a run-time stack integrity check in debug configuration and trigger a run-time diagnostic.

Although I don't direct connection to the 'alloca' being standard or not. There are perfectly _standard_ features that produce undefined behavior in circumstances "where making it work would be inconvenient". Like, for example, the range of 'ptrdiff_t' is not required to be sufficient for any [otherwise legal] pointer subtraction operation, and trying to subtract pointers which are too far apart produces UB.

--
Best regards,
Andrey Tarasevich
.



Relevant Pages

  • Re: What is a stack frame?
    ... There is no need for a separate "this frame" pointer. ... In any case, the more general term, which covers what a C compiler ... hardware-provided stack to implement the stack-like data structure ... manner since the current stack frame is "deformed" by alloca. ...
    (comp.lang.c)
  • Re: Do buffers always start with the lowest memory address being the first element?
    ... > The C standard does not assume a downward-growing stack, ... > an upward-growing stack. ... C allows but does not require that the array produced ... > machine depends on both the C compiler and the machine. ...
    (comp.lang.c)
  • Re: Criticisms?
    ... VLAs give you more than just that one particular feature. ... For alloca() to be reliable, the compiler has to recognize calls ... problem is that each allocacall adjusts the stack while the ...
    (comp.lang.c)
  • Re: FindFirstFile Possible Memory Leak
    ... for compiler variables that stack data is only ... function called alloca. ... This was suppose to allocate a local buffer on the stack and return its ... architectures, the stack pointer can be changed without losing your ...
    (microsoft.public.vb.general.discussion)
  • Re: FindFirstFile Possible Memory Leak
    ... Loop optimization and deeper parsers for ... for compiler variables that stack data is only ... stack pointer. ... function called alloca. ...
    (microsoft.public.vb.general.discussion)