const, volatile, etc [was Re: #defines with parameters]

Henry Spencer henry at utzoo.uucp
Tue Dec 20 08:57:26 AEST 1988


In article <422 at aber-cs.UUCP> pcg at cs.aber.ac.uk (Piercarlo Grandi) writes:
>As somebody else has remarked to you, in the classic era of C, long since
>dead, it was *unthinkable* that the compiler would be much more than a clever
>translator...

Curious, it was never unthinkable for me.  In fact, it's never been true,
given some of the peephole optimizations that even the original Ritchie
compiler was quite happy to do.

>After all, the Ritchie PDP-11 compiler was known as the "Standard C Compiler"
>for some reason, wasn't it?

I never heard it called that, actually, that I recall.  I've only been
using it since 1975, mind you.

>Register, +=, ++, are all sure signs that C was meant to be compiled by a simple
>compiler that relied on the programmer to use such constructs to help code
>generation.

Not really.  For one thing, operators like += (originally =+) are a
significant convenience even without any code-generation implications.
For another, you've missed a crucial distinction:  some of these operators
make it *possible* for a relatively simple compiler to generate good code,
given a clever programmer.  That does not imply that this was the only
mode of operation contemplated; some of DMR's own comments here and there
specifically indicate that he anticipated higher optimization later.

>Just a moment. Ritchie never explicitly did allow aggressive optimization.

Nor did he disallow it.

>... Ritchie introduced
>"register" in Classic C, not "volatile", after all, and this *means*
>something.  If he had meant aggressive optimization to be allowed, he might
>not have introduced "register"...

You are confusing *allowing* aggressive optimization with *requiring* it.
DMR put "register" in so that good code could be generated without major
optimization, but it was never meant to preclude more sophisticated means.
DMR himself observes in K&R1 that improved optimization might render the
"register" keyword unnecessary.

>he would have surely deemed "volatile"
>absolutely necessary, the more so as he used C to write, of all things,
>Unix's device drivers.

Dennis didn't set out to solve all the world's problems right from the
beginning.  If he thought about the issue, he probably assumed that it
would be dealt with, by him or someone else, when the problem began to
become too serious for simple workarounds.  It has been.

>    implemented, and used.
>
>On PCs, on PCs...

I don't understand this interjection.  If you intend to imply that my views
have been formed on PCs, this is laughable -- I've never compiled a C
program on a PC in my life.  (Well, I think I compiled a five-line one
on a PC running Coherent once, after I asked Randall Howard whether I
could try to crash it and he said "go ahead".  Famous last words... :-))
I learned C on a pdp11 with the Ritchie compiler under V5 (later V6 and
V7).

>    Might one ask how long you have been using C, Mr. Grandi?
>
>Regularly, since 1980 (of course I had already bought K&R as soon as it was
>out).  Probably my main impulse in extolling the virtues of Classic C is
>therefore plain old nostalgia for the good ol' days of V7 Unix and C...

What good ol' days?  "The thing history teaches us is that there never
were any good old days."  utzoo was a pdp11 running V7 until about 6
months ago.  The 11 is now our terminal server, so we still use the old
compiler on occasion for maintaining its software.  As I alluded to above,
C has been my major programming language since 1975.  I'm afraid that
I can't get nostalgic over a "Classic C" that never was.
-- 
"God willing, we will return." |     Henry Spencer at U of Toronto Zoology
-Eugene Cernan, the Moon, 1972 | uunet!attcan!utzoo!henry henry at zoo.toronto.edu



More information about the Comp.lang.c mailing list