"handy.h"
Mark Brader
msb at lsuc.UUCP
Fri Sep 6 02:55:20 AEST 1985
Michael Baldwin (whuxl!mike) suggests, among others:
> #define NELEM(arr) (sizeof (arr) / sizeof *(arr))
> #define LAST(arr) ((arr) + NELEM(arr))
> for (pp = potato; pp < LAST(potato); pp++)
and
> #define COPY(a,b) strncpy(a,b,sizeof a)
These are dangerous. LAST is misnamed, because it points to the
space after the last element. If used, it should be called
something like AFTERLAST.
And with COPY, there is a temptation to call it with arguments of the
wrong type. Can't you just see somebody writing
fun(s)
char s[];
{
char temp[PLENTY_BIG];
...
COPY (s, temp); /* WRONG */
}
and wondering why only the first few bytes were copied?
Mark Brader
More information about the Comp.lang.c
mailing list