Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site lsuc.UUCP Path: utzoo!utcs!mnetor!lsuc!msb From: msb@lsuc.UUCP (Mark Brader) Newsgroups: net.lang.c Subject: Re: "handy.h" Message-ID: <782@lsuc.UUCP> Date: Thu, 5-Sep-85 12:55:20 EDT Article-I.D.: lsuc.782 Posted: Thu Sep 5 12:55:20 1985 Date-Received: Thu, 5-Sep-85 14:19:21 EDT References: <10200006@ada-uts.UUCP> <532@linus.UUCP> <699@whuxl.UUCP> Reply-To: msb@lsuc.UUCP (Mark Brader) Organization: Law Society of Upper Canada, Toronto Lines: 29 Summary: Some of those suggestions are dangerous 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