Calico
|
Compatibility header for alloca
.
More...
Compatibility header for alloca
.
This header provides an alloca
-like function using variable-length arrays (VLAs), a built-in alloca
function, or using malloc
.
Two functions are provided:
cal_alloca(type, var, count)
cal_freea(var)
These functions should always be used like this:
void my_function(size_t count) { cal_alloca(double, mybuf, count);
do something with mybuf ... cal_freea(mybuf); }
Do not use cal_alloca
anywhere except in the outermost scope of a function, as VLAs and alloca have different lifetimes. Additionally, cal_freea
must (and can only) be called right before the function returns. Using longjmp
with to jump out of any function that uses cal_alloca
causes undefined behavior.
This header can be included multiple times.