P99

◆ P99_NEW

#define P99_NEW (   ...)    P99_IF_LT(P99_NARG(__VA_ARGS__), 2)(P00_NEW(__VA_ARGS__))(P00_NEW_ARGS(__VA_ARGS__))

Allocate an element of type T as given by the first argument and initialize it with the remaining arguments, if any.

This supposes that the argument list is of the form

T [, OTHER_PARAMETERS]

and that a function or macro named T_init exists where T_init is just the concatenation of the type name T and ‘_init’. Thus T must be a typename that consists of just one token: ‘signed’ would work but ‘signed long’ would not.

The T_init function must have a signature that is compatible to one of

T* T_init(T* p);
T* T_init(T*p, OTHER_PARAMETERS);
  • it must accept a pointer to T as a first argument
  • it must be robust to the possibility of receiving a null pointer through that first argument (indicating an error condition)
  • it should return the same pointer p
  • it may accept additional arguments which may then be passed through from the call to P99_NEW
Returns
value is a pointer to a newly allocated and initialized object of type T, or (T*)0 if the allocation failed.
See also
P99_CALL_DEFARG if you want to provide default arguments to the T_init function.

Definition at line 314 of file p99_new.h.

p
P00_CLAUSE2 p(P00_WEAK1(p00_cb))(P00_WEAK2(p00_cb)) pp99_callback_stack p00_at_quick_exit