const, volatile, etc [was Re: #defines with parameters]
Griff Smith
ggs at ulysses.homer.nj.att.com
Fri Dec 2 01:55:19 AEST 1988
In article <9016 at smoke.BRL.MIL>, gwyn at smoke.BRL.MIL (Doug Gwyn ) writes:
> "volatile" also serves a need. In fact, it directly addresses one of
> the comments I saw earlier today in this newsgroup, about use of C for
> accessing device registers. Again, it is transparent to virtually all
> existing code, it addresses a real need, and it can be ignored by anyone
> who does not specifically need it. What is your objection to it?
I agree, and I don't object, but some brief encounters with an ANSI
compiler make me worry about it a bit. The problem is that the
existence of the volatile qualifier makes it possible to do
optimizations that were previously forbidden (or at least difficult to
slip past the customers). I blew several hours discovering that a flag
set by a signal handler had been optimized out of existence because it
wasn't declared volatile. If I were writing new software I would be
aware of the problem and use the proper declaration, but what am I to
do about fixing all the old stuff that now has subtle errors caused by
optimizations that used to be illegal?
The response I got from a C++ guru around here wasn't encouraging: he
suggested declaring everything volatile and ignoring the issue. Maybe
he's right, but that attitude could easily lead to a habit of forcing
all declarations to include the volatile qualifier just to avoid a `silly'
rule. This would negate any efficiency improvements the compiler
designers were trying to achieve.
Do any of you have some practical experience, plus suggestions for
living in the brave new ANSI-C world?
--
Griff Smith AT&T (Bell Laboratories), Murray Hill
Phone: 1-201-582-7736
UUCP: {most AT&T sites}!ulysses!ggs
Internet: ggs at ulysses.att.com
More information about the Comp.lang.c
mailing list