>So I've been wondering about variable length arrays from c99 for a while 
>now. They seem to me like a good way to avoid lots of trivial calls to 
>malloc/free at least for smaller arrays that aren't going to blow up the 
>stack. That said I don't see them being used.
>
>The promise of them seems to be 'easy', dynamic, stack allocated memory and 
>improved readability. That said, using vla's avoids the work on malloc that 
>creates a hostile (strict) environment, like junking and whatnot. Also there 
>is the portability stuff, I'm not sure if all the platforms that openbsd 
>runs on are using a compiler that supports them yet.
>
>gcc 4.2 in base seems to support them well enough, though I note that the 
>gcc website says that some corner cases were fixed in version 4.5 which I 
>haven't investigated yet.
>
>So what do you guys think? VLA's, are they good, bad, evil, stupid, all of 
>the above?

alloca() re-invented.

>From the alloca(3),man page:

BUGS
     The alloca() function is slightly unsafe because it cannot ensure that
     the pointer returned points to a valid and usable block of memory.  The
     allocation made may exceed the bounds of the stack, or even go further
     into other objects in memory, and alloca() cannot determine such an
     error.  Avoid alloca() with large unbounded allocations.

alloca(3) was considered slightly unsafe, because use if it was rare.  Your
mail strikes so widely, feel free to modify a whole system to use this instead
of malloc.  Then argue your point, and lose...

Reply via email to