Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.musoftware.de!wum.musoftware.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Neil Cerutti Newsgroups: comp.lang.c Subject: Re: A question for this group... Date: 27 Jun 2012 13:49:13 GMT Organization: Norwich University Lines: 34 Message-ID: References: <61803198-a3b7-4cf7-a615-a9941d9393ba@googlegroups.com> <24bb4002-32ec-4fe5-9971-7d9683ad5029@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: individual.net nQzYbuAhOWxPY/C/NvD4wwmMC3dAhllRDuKubbpMxerErWCbdcBpyPsoVAyW9QDhY2 Cancel-Lock: sha1:B4yzaP5h/sf0vjk6sVBloj3VXMk= User-Agent: slrn/0.9.9p1/mm/ao (Win32) Xref: csiph.com comp.lang.c:22862 On 2012-06-26, nick_keighley_nospam@hotmail.com wrote: >> >> Don't stick your fingers in light sockets. > > this is a poor analogy. We're actually talking about code like > > printf("%d %d %d",a++,a++,++a); > > and the responses *aren't* "Don't Do That". Its "thats > undefined behaviour, its outcome can't be usefyully predicted". > IMHO analysing code like the above for a particular compiler is > time wasted. Not just for the naive and childish poster (as you > insist we treat them) but for anyone. While K&R sometimes urges learners to try out different strategies to find out what their particular implementation does with odd constructs, e.g., Exercise 1-2, in this case they agree with the most common responses in this newsgroup. They give the technical reason that constructs like this are undefined, but they further say that knowing the result of expressions like a[i] = ++i on your implementation is, in fact, evil. The moral is that writing code that depends on order of evaluation is a bad programming practice in any language. Naturally, it is necessary to know what things to avoid, but if you don't know how they are done on various machines you won't be tempted to take advantage of a particular implementation. Do not eat of that fruit, my friends. -- Neil Cerutti