Path: utzoo!attcan!uunet!codonics!bret From: bret@codonics.COM (Bret Orsburn) Newsgroups: comp.lang.c Subject: Re: Compilers and programming style (was Re: A question of style) Message-ID: <660@codonics.COM> Date: 12 Jan 90 04:07:01 GMT References: <2283@dataio.Data-IO.COM> <534@bbxsda.UUCP> <2288@dataio.Data-IO.COM> <544@bbxsda.UUCP> Reply-To: bret@codonics.com (Bret Orsburn) Organization: Codonics, Inc., Middleburg Heights, OH Lines: 41 In article <544@bbxsda.UUCP> scott@bbxsda.UUCP (Scott Amspoker) writes: > >I currently don't have the >ANSI draft at my disposal but I do have compilers that claim >to be ANSI compatible with reasonably good documentation. >None of this discusses any semantics for "*p;". I don't know about ANSI, but in K&R I, "*p" is a trivial case of an expression (page 214) and "*p;" is a statement (page 218). To treat them otherwise is to make them a Special Case, which I hold to be a Prima Facie Evil, only to be considered if it is the lesser of N evils, where N >= 2. As far as C is concerned, the semantics of the operation are the same as they would be in a non-trivial context. The memory location is read, and precisely nothing is done with the contents. This is a handy thing for tickling hardware. On the machine level, the semantics are whatever the hardware designer decided to make them. Reading a memory location, after all, is mostly just a matter of setting up the address bus and issuing a read pulse. For example: I worked on a design where a read from a certain location caused a latch to be reset. The latch was used in an interprocessor communication scheme. This is not a unique instance. I can think of three designs like this right off the top of my head. As someone else pointed out, this same objective can be accomplished by assigning the result to a temporary variable. However, that is (1) not more syntactically correct, (2) is only marginally safer where optimization is concerned, (3) wastes machine cycles. (OK, that is not a popular subject. Just remember this the next time you're waiting for your computer to finish its RAM test.) Note that nobody on either side of this thread has suggested taking this nit out of "lint"; lint (traditionally) has a very different mission than does "cc". To paraphrase somebody: If we did not have a C that behaved this way, we would surely have to invent one. -- ------------------- bret@codonics.com uunet!codonics!bret C Is Not Baroque Bret Orsburn Don't Fix It