| www.delorie.com/gnu/docs/glibc/libc_58.html | search |
![]() Buy the book! | |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
In GNU C, you can replace most uses of alloca with an array of
variable size. Here is how open2 would look then:
int open2 (char *str1, char *str2, int flags, int mode)
{
char name[strlen (str1) + strlen (str2) + 1];
stpcpy (stpcpy (name, str1), str2);
return open (name, flags, mode);
}
|
But alloca is not always equivalent to a variable-sized array, for
several reasons:
alloca
remains until the end of the function.
alloca within a loop, allocating an
additional block on each iteration. This is impossible with
variable-sized arrays.
Note: If you mix use of alloca and variable-sized arrays
within one function, exiting a scope in which a variable-sized array was
declared frees all blocks allocated with alloca during the
execution of that scope.
| webmaster donations bookstore | delorie software privacy |
| Copyright © 2003 by The Free Software Foundation | Updated Jun 2003 |