Path: utzoo!utgpu!watmath!clyde!att!ulysses!ggs
From: ggs@ulysses.homer.nj.att.com (Griff Smith)
Newsgroups: comp.lang.c
Subject: Re: const, volatile, etc [was Re: #defines with parameters]
Message-ID: <10919@ulysses.homer.nj.att.com>
Date: 1 Dec 88 15:55:19 GMT
References: <674@quintus.UUCP> <117@halcdc.UUCP> <468@auspex.UUCP> <9016@smoke.BRL.MIL>
Distribution: eunet,world
Organization: AT&T Bell Laboratories, Murray Hill
Lines: 32

In article <9016@smoke.BRL.MIL>, gwyn@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@ulysses.att.com