P99

◆ P99_CALLOC

#define P99_CALLOC (   T,
 
)

A type oriented replacement for calloc.

This similar to P99_MALLOC with the extra feature that the allocated space is initialized with the default as if the variable or array had been declared static.

This macro receives one or two arguments. The first is a type expression that is evaluated for the size of the type and used to construct a default initializer for the type. The second is optional and controls how may objects of the type should be created.

double * a = P99_CALLOC(double, 10); // allocate and initialize an array of 10 double
node * n = P99_CALLOC(node); // allocate and initialize one new node

Observe here that the double array a is initialized with the default initializer 0.0 for doubles. As on certain platforms 0.0 might not be represented by an all-zero-bit object, this might or might not be different from using plain calloc.

For n the advantage might be that the type node has pointer fields. These then are correctly initialized to null pointers. As on certain platforms null pointers might not be represented by an all-zero-bit object, this might or might not be different from using plain calloc.

Remarks
argument 0 should correspond to a type that is not a VLA.

Definition at line 268 of file p99_new.h.

P99_CALLOC
#define P99_CALLOC(T, N)
A type oriented replacement for calloc.
Definition: p99_new.h:268