evilness of alloca!

Doug Gwyn gwyn at smoke.BRL.MIL
Wed Apr 26 18:39:33 AEST 1989


In article <19305 at adm.BRL.MIL> rbj at dsys.icst.nbs.gov (Root Boy Jim) writes:
>? From: Doug Gwyn <gwyn at smoke.brl.mil>
>? We just went over that.  alloca() is not available on some systems for
>? good and sufficient reasons.  I would think that any sane programmer
>? would avoid it like the plague.
>So they get your version.

No, my alloca() emulation doesn't work at all for some C implementations
and it can be outwitted even on a "nice" architecture.  It's strictly
for emergency use if you don't have alloca() and run into code that
relies on it, until you can get around to fixing the code.

>Likewise, bending over backwards to force a problem into the malloc/free
>paradigm when it is expressed more naturally in terms of alloca is merely
>being pedantic.

Avoidance of alloca() is NOT a matter of style (what you call a "religious
issue"); it's a matter of practicality.  malloc()/free() (also calloc() and
realloc()) is the only portable method for dynamic storage allocation in C.
If you want your code to be maximally portable, which I hope is normally
the case, you must not rely on alloca().



More information about the Comp.unix.wizards mailing list