scope of malloc

Steve Summit scs at adam.mit.edu
Thu Nov 8 10:43:15 AEST 1990


In article <1990Nov07.134942.7355 at virtech.uucp> cpcahil at virtech.UUCP (Conor P. Cahill) writes:
>If you just want the pointer to be around during the function, you can
>use alloca() which allocates the data on your stack.

Correction: "If you just want the pointer to be around during the
function and you want the program to be unportable...", as Doug
has just reminded us.

>This function is 
>usually hidden in the libPWB.a library.

...except under BSD, where it's right there in libc.a, and under
many other systems, where it doesn't exist at all.

The FAQ contains a bit more information on alloca.  The summary,
which bears repeating, stands: "alloca cannot be used in programs
which must be widely portable, no matter how useful it might be."

                                            Steve Summit
                                            scs at adam.mit.edu



More information about the Comp.lang.c mailing list