[Issue 3822] alloca() can return the same address inside a function

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Feb 18 12:32:40 PST 2010


http://d.puremagic.com/issues/show_bug.cgi?id=3822



--- Comment #2 from bearophile_hugs at eml.cc 2010-02-18 12:32:38 PST ---
(In reply to comment #1)
> I've never used alloca so I'm not sure, so this is a guess:
> 
> alloca does stack allocation and the body of the for statement forms a scope on
> the stack (this in this case contains no named variables). I'm guessing that
> when that scope is exited, the allocation automatically gets deallocated.

You can be right, thank you. Then it's very good for Phobos docs to say that
alloca is relative to a scope and not to a function.

The description of alloca() that I have seen says:

The alloca() function allocates space in the stack frame of the caller, and
returns a pointer to the allocated block. This temporary space is automatically
freed when the function from which alloca() is called returns.

While if you are right D alloca frees space when the scope of alloca ends and
not when the function ends.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list