Compilers and programming style (was Re: A question of style)
Bret Orsburn
bret at codonics.COM
Fri Jan 12 15:07:01 AEST 1990
In article <544 at bbxsda.UUCP> scott at 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 at codonics.com
uunet!codonics!bret C Is Not Baroque
Bret Orsburn Don't Fix It
More information about the Comp.lang.c
mailing list