...
Code Block | ||
---|---|---|
| ||
#define MALLOC_ARRAY(number, type) \
((type *)malloc(number * sizeof(type)))
|
reduces
...
the
...
chance
...
of
...
error
...
in
...
an
...
allocation
...
expression:
Code Block | ||
---|---|---|
| ||
enum { N = 16 };
widget *p;
/* ... */
p = MALLOC_ARRAY(N, widget); /* OK */
|
...
A small collection of macros can provide secure implementations for common uses for the standard memory allocation functions.
...