Top 5

Denis Koroskin 2korden at gmail.com
Wed Oct 8 16:25:18 PDT 2008


On Thu, 09 Oct 2008 03:14:33 +0400, bearophile <bearophileHUGS at lycos.com>  
wrote:

> Sean Kelly:
>> We can generally use alloca for this in D, so I don't consider this a
>> major issue.  Be pretty cool to have it in-language though.
>
> Time ago I have shown this bug that I think may be of alloca():
>
> import std.c.stdlib: alloca;
> void main() {
>     const int n = 8;
>     for (int i; i < 2; i++)
>         printf("%p\n", alloca(n));
> }
>
> Error: it prints two times the same address.
>
> (I also think alloca of DMD is currently not much fast, compared to the  
> allocation of variable length arrays of C99 of GCC, but I don't have  
> hard data to support this at the moment).
>
> Bye,
> bearophile


Is this really an error? "for" body creates a new scope and alloca'ted  
memory is automatically released once you leave the block.



More information about the Digitalmars-d mailing list