6 ms·
To avoid the duplication, with risk of mismatch, and to make it one less thing for the reader to check, I have #define NEW(a) ((a) = emalloc(sizeof(*(a))))
by ralph 15y ago
To avoid the duplication, with risk of mismatch, and to make it one less thing for the reader to check, I have
#define NEW(a) ((a) = emalloc(sizeof(*(a))))
NEW(foo);
Similarly with NEW0() and ecalloc(). Yes, the macro uses the parameter more than once, and yes it's another macro for the reader to grasp, but it's a simple one and NEW() is used so widely it's soon learnt.