Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site proper.UUCP Path: utzoo!linus!decvax!harpo!seismo!hao!hplabs!intelca!proper!gam From: gam@proper.UUCP (Gordon Moffett) Newsgroups: net.lang.c Subject: subscripting constant arrays Message-ID: <834@proper.UUCP> Date: Wed, 11-Jan-84 22:36:23 EST Article-I.D.: proper.834 Posted: Wed Jan 11 22:36:23 1984 Date-Received: Sat, 14-Jan-84 03:56:40 EST Organization: Proper UNIX, San Leandro, CA Lines: 19 Recently I came across the following code fragment: char *cp, ch[10]; unsigned u; . . for (cp = ch; u != 0; u >>=4) { *cp++ = "0123456789ABCDEF"[u & 0xF]; } Shocking isn't it? But the subscripting of the constant array is legal K&R syntax (see sec 7.1), so this does work on all valid compilers. As a stylistic note, I would suggest putting the string in parentheses to emphasize its use as an expression: *cp++ = ("0123456789ABCDEF")[u & 0xF]; This made it clearer to me, anyway (former APL hacker...).