Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84 exptools; site whuxl.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxt!houxm!whuxl!mike From: mike@whuxl.UUCP (BALDWIN) Newsgroups: net.lang.c Subject: Re: "handy.h" Message-ID: <699@whuxl.UUCP> Date: Tue, 3-Sep-85 14:28:57 EDT Article-I.D.: whuxl.699 Posted: Tue Sep 3 14:28:57 1985 Date-Received: Wed, 4-Sep-85 07:12:15 EDT References: <10200006@ada-uts.UUCP> <532@linus.UUCP> Organization: AT&T Bell Laboratories, Whippany Lines: 32 >I'm interested in coming up with an include file, say "handy.h", >which declares a lot of commonly useful "stuff". These can be "handy": #define NELEM(arr) (sizeof (arr) / sizeof *(arr)) #define LAST(arr) ((arr) + NELEM(arr)) e.g., struct vegetable potato[] = { "burbank", 0.34, "new", 3.44, "hot", 0.12, }; then struct vegetable *pp; for (pp = potato; pp < LAST(potato); pp++) or int i; for (i = 0; i < NELEM(potato); i++) I also like the usual string stuff: #define EQUAL(a,b) !strcmp(a,b) #define EQUALN(a,b,n) !strncmp(a,b,n) #define PREFIX(a,b) !strncmp(a,b,strlen(a)) #define COPY(a,b) strncpy(a,b,sizeof a) -- Michael Baldwin AT&T Bell Labs {at&t}!whuxl!mike