On 18/09/2009, ron minnich <[email protected]> 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: > 1. you're repeating the same code over and over > 2. 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 -- Maciej Pijanka, PLD-Linux Developer, Reg Linux user #133161 POE/Perl user _______________________________________________ flashrom mailing list [email protected] http://www.flashrom.org/mailman/listinfo/flashrom
