Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!cmcl2!brl-adm!adm!mrd@clutx.clarkson.EDU From: mrd@clutx.clarkson.EDU (Michael R. DeCorte) Newsgroups: comp.lang.c Subject: Possible C Anomaly Message-ID: <9601@brl-adm.ARPA> Date: Sat, 3-Oct-87 02:35:31 EDT Article-I.D.: brl-adm.9601 Posted: Sat Oct 3 02:35:31 1987 Date-Received: Tue, 6-Oct-87 07:24:52 EDT Sender: news@brl-adm.ARPA Lines: 61 I missed the comment ]] No! Consider that you're doing (one way) "k = --k". You still don't know so I might simply missing something but I still believe this is correct. It does not matter which is evaluted first. k will be assigned whatever the rvalue is and the rvalue of --k is the same as (k-1). Therefore in this context --k is the same as (k-1). Now I will admit that this is not the nicest way of doing this and will cause problems with anything much more complicated but I wanted to modify the the statement as given by the original author little as possible. one of the possible solutions given by Mike Palmer was ] (k > 1) ? k-- : (k = 1); This is correct but I don't care for the style simply because I view ? to be an expression but it doesn't really matter. The other possibility given by Mike Palmer was ] (k > 1) ? k-- :; This is not really correct. What if k <= 0? Now you could argue that this will never happen but it is not what the original statement was. David Goodenough offered two solutions. The first was identical to one of mine but second solution was > if (k > 1) > k--; the problem with this is the same as Mike Palmer's. What if k <=0? The way I would actully code it is rather non C'ish if (k > 1) { k--; } else { k = 1; } And to give yet another solution you could also try if (k-- <= 1) { k = 1; } or (k-- <= 1) ? k = 1 : ; Although not very readable this has the advantage that it will very good with many cpu's and compilers but very bad with others. -------------------------------------------------------------- All opinions and/or comments stated here are my own and are not in any way related to Clarkson U. Michael DeCorte mrd@clutx.clarkson.edu