26 May
2012
26 May
'12
2:24 p.m.
On Sat, May 26, 2012 at 03:59:12PM +0200, Alexander Voigt wrote:
Hi 123,
why not introducing a macro like
#define LENGTH(X) (sizeof (X) / sizeof (X)[0])
which could be used in all these for loops? I think this would make the code simpler and less error prone.
I'm not a fan of hiding this in macros. Something like struct foo * f = malloc(sizeof(struct foo) * 10); for(int i = 0; i < LENGTH(f); i++) { looks even more unsuspicious than with the sizeof stuff visible. Cheers, Johannes