A different view of volatile

Brian T. Schellenberger bts at sas.UUCP
Tue May 3 13:19:00 AEST 1988


In article <8013 at pur-ee.UUCP> hankd at pur-ee.UUCP (Hank Dietz) writes:
|
|converting "a=b;a=b" into "a=b" often can be KNOWN SAFE.  You
|only have to use register when the compiler wouldn't otherwise have noticed.
|
|Suppose that a is declared "int a;" and that ALL references to a can be
|seen.  If the address of "a" is never taken, then all references to "a" can
|be safely removed; likewise, if "&a" is taken, only references to "a" where
|"&a" reaches cannot be removed.  I'm oversimplifying a bit, but the basic
|point is that the analysis to determine this for most LOCAL NON-POINTER
|variables is quite easy, hence "register" helps only a little for local
|variables.  It would be a big help for externs, statics, and for function
|interfaces because it is very expensive (at least) for the compiler to see
|all references when some references might be in other compilation units
|(other files).
|

No, no.  If you assume that it is "volatile" in the absense of of "register",
you can't do this at all.  "a=b;a=b" can't be optimized in this case because
the value of "b" may change between the two statement due to an asynchronus
process.  THAT is what "volatile" means.

What you are talking about--and what "register" implies--is NOALIAS, that
much-maligned and now defunct keyword.  It might be good to suggest for the
C-92 standard that the next ANSI committee add semantic meaning to "register"
allowing it to apply to other situations than it currently does in order to
provide the same functionality as NOALIAS in a keyword everybody feels more
comfortable with.

Of course, as Mr. Dietz points out, "register" is redundant for this purpose
for simple local variables anyway, since the compiler can usually figure it 
out.  Which is probably just as well, since "register" already means something
else for simple local variables.

The proposal to reuse "register" in this way seems very much in the "spirit of
C", but I consider this to be the worst single aspect of the language; I'd 
rather see NOALIAS brought back than overload "register" in this way meself.
Understood that this is probably a minority position; please skip the non-
informative flames (flames with actual information are ok).
-- 
                                                         --Brian.
(Brian T. Schellenberger)				 ...!mcnc!rti!sas!bts

. . . now at 2400 baud, so maybe I'll stop bothering to flame long includes.



More information about the Comp.lang.c mailing list