Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!decvax!tektronix!tekmdp!bronze!stevesu From: stevesu@bronze.UUCP (Steve Summit) Newsgroups: net.lang.c Subject: Re: Multiple character "character constants" Message-ID: <816@bronze.UUCP> Date: Thu, 6-Oct-83 14:19:13 EDT Article-I.D.: bronze.816 Posted: Thu Oct 6 14:19:13 1983 Date-Received: Sat, 8-Oct-83 05:07:48 EDT References: turtleva.234 Lines: 33 I'm sure I won't be the only one to post a followup on this, but I haven't seen any yet, so here goes. Multiple-character character constants are a horrible idea. Whenever I see one, I have no idea whether or not it's a typo. If it's a typo, I don't know if the extra characters are extraneous or if a string was intended. If it's not a typo, I don't know if the programmer knew what he was doing, or if the program has a chance of working on my machine. Character constants are explicitly defined to be a single character. (Kernighan and Ritchie, page 35, and again on page 180.) On the other hand, Appendix A, under "portability considerations" notes (page 212) that "Since character constants are really objects of type _i_n_t, multi-character character constants are permitted. The specific implementation is very machine dependent, however, because the order in which characters are assigned to a word varies from one machine to another." I didn't really understand why multi-character constants would be useful in the example given in the original article. (I admit that I didn't try very hard.) I would never use a machine-dependent "feature" like that. Portability is a very important issue. I jump back and forth between vaxes and 11's, and I like to take my programs with me. I only write machine dependent code when I have to (when I'm using assembly language to do something I can't do in C, or writing code that deals with object file format.) If you really want to do a switch on multiple-character sequences, use a bunch of strcmp's or a hash function to convert a genuine string to a genuine integer. Steve Summit tektronix!tekmdp!stevesu