Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84 SMI; site sun.uucp Path: utzoo!linus!decvax!decwrl!sun!guy From: guy@sun.uucp (Guy Harris) Newsgroups: net.lang.c Subject: Re: c programming style - READ THIS Message-ID: <2565@sun.uucp> Date: Tue, 6-Aug-85 01:50:31 EDT Article-I.D.: sun.2565 Posted: Tue Aug 6 01:50:31 1985 Date-Received: Wed, 7-Aug-85 03:18:28 EDT References: <11570@brl-tgr.ARPA> <935@teddy.UUCP> <1286@uwmacc.UUCP> <2439@sun.uucp> <734@lsuc.UUCP> <1095@diku.UUCP> Organization: Sun Microsystems, Inc. Lines: 24 > Well, you should know that `++' and `--' *ONLY* works on variables of type > scalar, where a there is a defined successor or predecessor No, I didn't know that. Then again, neither did Kernighan nor Ritchie. See the sixth paragraph under the heading "7.2 Unary operators" in the C Reference Manual (p. 187 of *The C Programming Language* - I'm sick of typing in quotes from the CRM for people who won't go read their own copy; you've got the reference, go read it) wherein it states quite clearly that "++" and "--" work on any type which can have 1 added to it (type "scalar"? There's no "scalar" in the index to *The C Programming Language.* Sure you're not thinking of Pascal?). > (You can compare these operators as the Pascal functions pred() and succ()), No, you can't. My J&W says that "succ" and "pred" apply to all scalar types except "real". My K&R says that "++" applies to any type which you can add 1 to, which *includes* "float" and "double" and does *not* include "enum". (Besides, "++" has a side effect, while "succ" is a function, but we won't discuss that.) The fact that "a + 1" in C and "succ(a)" in Pascal happen yield the same answer if "a" is an integral type in C and a "integer" or "char" in Pascal shouldn't tempt you into stretching the similarity past its breaking point. Guy Harris