On 18/09/2009, ron minnich rminnich@gmail.com wrote:
OK, if you're going to do this:
if (x) { message exit }
all over the place, why not do this instead:
void *xalloc(size_t amount, char *msg) { void *ret = alloc(amount); if (! ret) { fprintf(stderr, "%s: Alloc of %d bytes failed\n", msg, amount); exit(1); } }
same for realloc.
Why? because:
- you're repeating the same code over and over
- you're not telling people where you failed, or how much you tried to
allocate this kind of fatal error should be informative
just a comment
if xalloc will be done as macro then its possible to use __LINE__ and __FILE__ values to show from where xalloc was called
#declare xalloc(a,b) xalloc(a,b,__FILE__, __LINE__)
or similar construction
just my 1e-30 of comments
best regards Maciej