calloc idiocy
Posted Aug 12, 2005 21:33 UTC (Fri) by
giraffedata (subscriber, #1954)
In reply to:
calloc idiocy by chad.netzer
Parent article:
kzalloc()
You, of course, meant to say "malloc(4 * sizeof(t))", but we get your point.
I'm pretty sure he meant what he wrote; it's what I would have written, anyway: an apples to apples comparison of two hypothetical designs for calloc(), one more readable than the other.
I find calloc(4, sizeof(t)) easier to read. It says rather explicitly that you're allocating space for 4 array elements, whereas calloc(4 * sizeof(t)) requires an extra mental step to go backwards through the arithmetic and say, "Aha. He's calculating how much memory a 4 element array would take."
I myself do even better. I use a macro thusly:
t * arrayOfT;
MALLOCARRAY(arrayOfT, 4);
(
Log in to post comments)