Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site ucbcad.UUCP Path: utzoo!linus!philabs!seismo!hao!hplabs!zehntel!tektronix!ucbcad!ucbesvax.turner From: ucbesvax.turner@ucbcad.UUCP Newsgroups: net.lang.c Subject: Re: subscripting constant arrays - (nf) Message-ID: <1318@ucbcad.UUCP> Date: Sun, 15-Jan-84 08:08:06 EST Article-I.D.: ucbcad.1318 Posted: Sun Jan 15 08:08:06 1984 Date-Received: Sat, 21-Jan-84 01:21:22 EST Sender: notes@ucbcad.UUCP Organization: UC Berkeley CAD Group Lines: 22 #R:proper:-83400:ucbesvax:4800032:000:678 ucbesvax!turner Jan 14 12:23:00 1984 re: subscripting constant arrays . Not only can you say "0123"[i], and the like, but sizeof ("0123") reliably returns 5 (not 4--think.) This is even useful, occasionally--as when you wish to test if the first few chars of a string match some literal constant string. Example: #define MATCH(s,sc) (strncmp (s, sc, sizeof(sc)-1) == 0) if (MATCH (s, "add")) ... then becomes if (strncmp (s, "add", 3) == 0) Here, of course, if sc is not a literal or constant string, sizeof (sc) becomes sizeof (char *). The ideal MATCH macro would detect this and generate cc-warning code instead, but I'm not quite sure how to do that. --- Michael Turner (ucbvax!ucbesvax.turner)