🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.atari.st
Article #26946

Re: Megamax bug or crappy C ?

#26946
From: pes
Date: Thu, 21 May 1987 16:31
20 lines
1613 bytes
K&R have almost the identical example, at the end of chapter 2.  The quick
answer is, they're both right.  From K&R:

'In any expression involving side effects, thre can be subtle dependencies
on the order in which variables taking part in the expression are stored.
One unhappy situation is typified by the statement

  a[i] = i++;

The question is whether the subscript is the old value of i or the new.
The compiler can do this in different ways, and generate different answers
depending on its interpretation.  When side effects (assignment to actual
variables) takes place is left to the discretion of the compiler, since
the best order strongly depends on machine architecture.
  The moral of this discussion is that writing code which depends on order
of evaluation is a bad practice in any language.'

I'd say that applies to your slightly fancier example, as well, meself.
And I *believe* that even the proposed ANSI standard doesn't tighten this
up much, if at all -- though I don't track it very closely so may be wrong.
Technical Details
Message-ID: <1190@bath63.ux63.bath.ac.uk>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!rutgers!ll-xn!husc6!seismo!mcvax!ukc!dcl-cs!bath63!pes
References: <756@klipper.cs.vu.nl>

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!rutgers!ll-xn!husc6!seismo!mcvax!ukc!dcl-cs!bath63!pes
From: pes@bath63.UUCP
Newsgroups: comp.sys.atari.st
Subject: Re: Megamax bug or crappy C ?
Message-ID: <1190@bath63.ux63.bath.ac.uk>
Date: Thu, 21-May-87 12:31:33 EDT
Article-I.D.: bath63.1190
Posted: Thu May 21 12:31:33 1987
Date-Received: Sat, 23-May-87 08:16:30 EDT
References: <756@klipper.cs.vu.nl>
Reply-To: pes@ux63.bath.ac.uk (Paul Smee)
Organization: AUCC c/o University of Bath
Lines: 20