"handy.h"

BALDWIN mike at whuxl.UUCP
Tue Sep 10 06:48:27 AEST 1985


> > #define	NELEM(arr)	(sizeof (arr) / sizeof *(arr))
> > #define	LAST(arr)	((arr) + NELEM(arr))
> > #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.

Yeh, you're right.  LAST is too generic sounding.  Reminds me of
curses(3C), with move() and erase(), which conflict with routines of the
same name in plot(3X)!  But I still say the functions they perform
are easier to read (with suitable names) than the corresponding x+y/z...

> 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 */
> 	}

I don't know what to call this one.  But I still think it's useful.
It's not a general-purpose string copy macro; it's just useful when 
you want to copy a string to a safe place without scrogging the safe
place.  Hmm, maybe STRBUFSAVE?  Oh hell, mebbe I'll just use strncpy!

> Mark Brader

Hey!  *My* initials are MSB!  Wild.
-- 
						Michael Scott Baldwin
						AT&T Bell Labs
						{at&t}!whuxl!mike



More information about the Comp.lang.c mailing list